-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathMySQLConnect.java
More file actions
29 lines (25 loc) · 832 Bytes
/
MySQLConnect.java
File metadata and controls
29 lines (25 loc) · 832 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
29
package proj_mysqlconnect;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JOptionPane;
/**
*
* @author ErSKS
*/
public class MySQLConnect {
public static Connection conn;
public static Connection connectDb() {
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/java_db", "java", "");
System.out.println("Database Connected Successfully !");
return conn;
} catch (ClassNotFoundException | SQLException e) {
System.out.println(e.getMessage());
JOptionPane.showMessageDialog(null, "Database cannot be connected !");
System.exit(0);
}
return null;
}
}