-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConn.java
More file actions
42 lines (29 loc) · 1.13 KB
/
Conn.java
File metadata and controls
42 lines (29 loc) · 1.13 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
package bank.management.system;
import java.sql.*;
public class Conn {
Connection c;
Statement s;
public Conn(){
try{
Class.forName("com.mysql.cj.jdbc.Driver");
c = DriverManager.getConnection("jdbc:mysql://localhost:3306/bankmanagementsystem", "root", "1874prin");
s = c.createStatement();
System.out.println("Database Connected Successfully!");
} catch (ClassNotFoundException e) {
System.out.println("MySQL Driver not found: " + e);
} catch (SQLException e) {
System.out.println("Database connection error: " + e);
} catch (Exception e) {
System.out.println("Unexpected error: " + e);
}
}
public void closeConnection() {
try {
if (s != null) s.close();
if (c != null) c.close();
System.out.println("Database connection closed.");
} catch (SQLException e) {
System.out.println("Error closing connection: " + e);
}
}
}