-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDBConnect.java
More file actions
42 lines (32 loc) · 1.03 KB
/
DBConnect.java
File metadata and controls
42 lines (32 loc) · 1.03 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class DBConnect {
private static final String DRIVER = "com.mysql.cj.jdbc.Driver";
static final String URL = "jdbc:mysql://192.168.72.21:3306/thehub";
//User log in for DB
static final String USER = "TheHub";
static final String PASS = "$TheHub2023$";
Connection conn = null;
Statement st = null;
private static DBConnect instance;
DBConnect(){}
public static synchronized DBConnect getInstance() {
if (instance == null) {
instance = new DBConnect();
}
return instance;
}
public void dbConnect() {
try {
conn = DriverManager.getConnection(URL, USER, PASS);
st = conn.createStatement();
Class.forName(DRIVER);
System.out.println("Connecting to database...");
String sql = "USE thehub;";
st.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
}
}
}