ajout model BaseDeDonnees et Rappel
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package fr.iutfbleau.papillon.model;
|
||||
import org.mariadb.jdbc.MariaDbDataSource;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class BaseDeDonnees {
|
||||
|
||||
private static Connection connexion;
|
||||
|
||||
public static Connection getConnexion() {
|
||||
if (connexion == null) {
|
||||
try {
|
||||
MariaDbDataSource dataSource = new MariaDbDataSource();
|
||||
dataSource.setUrl("jdbc:mariadb://localhost:3307/papillon");
|
||||
dataSource.setUser("root");
|
||||
dataSource.setPassword("mdp");
|
||||
|
||||
connexion = dataSource.getConnection();
|
||||
System.out.println(" Connexion réussie !");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return connexion;
|
||||
}
|
||||
|
||||
public static void fermer() {
|
||||
try {
|
||||
if (connexion != null && !connexion.isClosed()) {
|
||||
connexion.close();
|
||||
System.out.println(" Connexion fermée.");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user