-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMySQLConnection.java
37 lines (29 loc) · 1.01 KB
/
MySQLConnection.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
31
32
33
34
35
36
37
import java.sql.SQLException;
import com.mysql.jdbc.Connection;
import java.sql.DriverManager;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public class MySQLConnection {
private String kullanıcı_adı = "root";
private String db_name = "donation";
private String host = "localhost";
private int port = 3307;
String url = "jdbc:mysql://" + host + ":" + port + "/" + db_name;
public Connection getmysql_connection() {
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(MySQLConnection.class.getName()).log(Level.SEVERE, null, ex);
}
try {
con = (Connection) DriverManager.getConnection(url, "root", null);
} catch (SQLException ex) {
Logger.getLogger(MySQLConnection.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(null,"Database bağlantısı kurulamadı");
System.exit(0);
}
return con;
}
}