-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetConnection.java
More file actions
27 lines (21 loc) · 830 Bytes
/
Copy pathGetConnection.java
File metadata and controls
27 lines (21 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package DBTest;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;
public class GetConnection {
public static Connection getConnection() throws Exception {
// set driver
Class<?> clazz = Class.forName("com.mysql.cj.jdbc.Driver");
InputStream is = clazz.getClassLoader().getResourceAsStream("testDB.properties");
Properties pro = new Properties();
pro.load(is);
String url = pro.getProperty("url");
String user = pro.getProperty("user");
String password = pro.getProperty("password");
String driverClass = pro.getProperty("DriverClass");
Connection connection = DriverManager.getConnection(url, user, password);
// return connection
return connection;
}
}