-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBConnect.java
More file actions
28 lines (25 loc) · 918 Bytes
/
DBConnect.java
File metadata and controls
28 lines (25 loc) · 918 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
28
package com.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBConnect {
private static Connection conn;
public static Connection getConn() {
try {
if (conn == null || conn.isClosed()) {
Class.forName("com.mysql.cj.jdbc.Driver");
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/e_books", // ⚠️ CHANGED to e_books
"root",
"your_mysql_password_here" // ⚠️ CHANGE THIS to your actual password
);
System.out.println("Database connected successfully!");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
}