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 46 47 48 49
|
package com.sdz.connection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class SdzConnection{
/**
* URL de connection
*/
private String url = "jdbc:postgresql://localhost:5432/Ecole";
/**
* Nom du user
*/
private String user = "postgres";
/**
* Mot de passe du user
*/
private String passwd = "postgres";
/**
* Objet Connection
*/
private static Connection connect;
/**
* Constructeur privé
*/
private SdzConnection(){
try {
connect = DriverManager.getConnection(url, user, passwd);
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 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 SdzConnection();
}
return connect;
}
} |
Partager