-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17_02_2025.java
30 lines (26 loc) · 1.06 KB
/
17_02_2025.java
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
// Placeholder for 17-02-2025.java
package university.management;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DatabaseConnector {
public static void main(String[] args) {
DatabaseConnector connector = new DatabaseConnector();
System.out.println("Connection status: " + (connector.getConnection() != null ? "Success" : "Failed"));
}
public Connection getConnection() {
final String DB_URL = "jdbc:mysql://localhost:3306/university_db";
final String USER = "admin";
final String PASS = "securepassword123";
Connection connection = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
connection = DriverManager.getConnection(DB_URL, USER, PASS);
} catch (ClassNotFoundException e) {
System.err.println("JDBC Driver not found: " + e.getMessage());
} catch (SQLException e) {
System.err.println("Connection failed: " + e.getMessage());
}
return connection;
}
}