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 38 39 40 41 42 43 44 45
| public final class Mysql {
/**
* URL de connection
*/
private static final String url = "jdbc:mysql://localhost:3306/jeu";
/**
* Nom du user
*/
private static final String user = "root";
/**
* Mot de passe du user
*/
private static String passwd = "root";
/**
* Objet Connection
*/
private static Connection connect;
/**
* Constructeur privé
*/
private Mysql(){
try {
connect = DriverManager.getConnection(url, user, passwd);
} catch (SQLException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Mysql problem.","Error",JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
}
/**
* Méthode qui va nous retourner notre instance
* et la créer si elle n'existe pas...
* @return
*/
public static Connection getInstance(){
if(connect == null){
new Mysql();
}
return connect;
}
} |
Partager