-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnexion.java
More file actions
34 lines (30 loc) · 1.13 KB
/
Copy pathConnexion.java
File metadata and controls
34 lines (30 loc) · 1.13 KB
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
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Connexion {
private static Connection connection = null;
public static Connection getConnection() {
if (connection == null) {
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
String url = "jdbc:ucanaccess://C:/Users/lenovo/Documents/BDProjetAya.accdb";
connection = DriverManager.getConnection(url);
System.out.println("Connexion réussie !");
} catch (Exception e) {
System.out.println("Erreur de connexion : " + e.getMessage());
e.printStackTrace();
}
}
return connection;
}
public static void closeConnection() {
try {
if (connection != null && !connection.isClosed()) {
connection.close();
System.out.println("Connexion fermée.");
}
} catch (SQLException e) {
System.out.println("Erreur lors de la fermeture : " + e.getMessage());
}
}
}