-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnectionClass.java
More file actions
45 lines (39 loc) · 1.22 KB
/
connectionClass.java
File metadata and controls
45 lines (39 loc) · 1.22 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
43
44
45
import java.sql.*;
public class connectionClass {
static final String URL = "jdbc:mysql://localhost:3306/empl_java_imp";
static final String USER = "root";
static final String PASS = "root";
private Connection conn;// returns it's object ie conn
public connectionClass() {
try {
this.conn = DriverManager.getConnection(URL, USER, PASS);
System.out.println("\nConnection Successful\n");
} catch (SQLException e) {
e.printStackTrace();
}
}
public PreparedStatement createPrepareStatement(String query) {
try {
return conn.prepareStatement(query);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
public Statement createStatement() {
try {
return conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
public void closeConnection() {
try {
if (conn != null) conn.close();
System.out.println("Connection closed.");
} catch (SQLException e) {
e.printStackTrace();
}
}
}