-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJdbcTools.java
More file actions
30 lines (25 loc) · 876 Bytes
/
JdbcTools.java
File metadata and controls
30 lines (25 loc) · 876 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
30
package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JdbcTools {
private static String jdbcUrl;
private static String user;
private static String password;
private static Connection connection = null;
public static Connection getConnection() throws SQLException {
// Charger le pilote
if(connection == null) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
jdbcUrl = "jdbc:mysql://localhost:3306/jdbc"; // URL de la base de données (changez-la en fonction de votre configuration)
user = "root"; // Nom d'utilisateur MySQL
password = ""; // Mot de passe MySQL
connection = DriverManager.getConnection(jdbcUrl, user, password);
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
}
}
return connection;
}
}