-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBConnection.java
More file actions
25 lines (24 loc) · 932 Bytes
/
Copy pathDBConnection.java
File metadata and controls
25 lines (24 loc) · 932 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
package eventsystem;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JOptionPane;
public class DBConnection {
private static final String URL = "jdbc:mysql://localhost:3306/event_system";
private static final String USER = "root";
private static final String PASS = "Mayar18181@";
public static Connection getConnection() {
Connection con = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection(URL, USER, PASS);
System.out.println("Database connected successfully!");
} catch (Exception e) {
JOptionPane.showMessageDialog(null,
"Database Connection Error:\n" + e.getMessage(),
"Connection Error",
JOptionPane.ERROR_MESSAGE);
}
return con;
}
}