59 lines
1.4 KiB
Java
59 lines
1.4 KiB
Java
![]() |
package fr.iutfbleau.projetIHM2021FI2.Model;
|
||
|
import java.sql.*;
|
||
|
import javax.swing.JOptionPane;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* La classe ConnexionBDD permet de se connecter à notre base de données.
|
||
|
*
|
||
|
* @version 1.0
|
||
|
* @author Anice TAJGALT, Gianni MANZARI, Alban DUMAS
|
||
|
*/
|
||
|
public class ConnexionBDD {
|
||
|
|
||
|
private static ConnexionBDD connexionInstance = null;
|
||
|
private Connection sqlCo;
|
||
|
|
||
|
//Constructeur
|
||
|
private ConnexionBDD() {
|
||
|
this.sqlCo = null;
|
||
|
this.connect();
|
||
|
}
|
||
|
|
||
|
// CONNEXION BDD TAJGALT
|
||
|
public void connect() {
|
||
|
try {
|
||
|
Class.forName("org.mariadb.jdbc.Driver");
|
||
|
try {
|
||
|
this.sqlCo = DriverManager.getConnection("jdbc:mariadb://dwarves.iut-fbleau.fr/tajgalt", "tajgalt", "tajgalt");
|
||
|
}
|
||
|
catch(SQLException e) {
|
||
|
System.err.println("Identifiants incorrects, vérifiez !");
|
||
|
}
|
||
|
}
|
||
|
catch(ClassNotFoundException e) {
|
||
|
JOptionPane.showMessageDialog(null, "Connexion Impossible !", "Connexion", JOptionPane.ERROR_MESSAGE);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// DECONNEXION BDD
|
||
|
public void close() {
|
||
|
try {
|
||
|
this.sqlCo.close();
|
||
|
}
|
||
|
catch(SQLException e) {
|
||
|
System.err.println("Impossible de se déconnecter");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static ConnexionBDD getInstance() {
|
||
|
if (connexionInstance == null) {
|
||
|
connexionInstance = new ConnexionBDD();
|
||
|
}
|
||
|
return connexionInstance;
|
||
|
}
|
||
|
|
||
|
public static Connection getSQLco() {
|
||
|
return connexionInstance.sqlCo;
|
||
|
}
|
||
|
}
|