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
|
public static Connection ouvrirConnexion()
{
try
{
// Charge le driver JDBC
String driver = "com.mysql.jdbc.Driver";
Class.forName(driver);
// Créer la connexion avec la base
String nomMachine = "localhost:3306";
String nomBase = "test";
String username = "root";
String password = "admin";
String url = "jdbc:mysql://"+ nomMachine +"/" + nomBase;
return DriverManager.getConnection(url, username, password);
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
System.err.println("Ne trouve pas le driver !!");
}
catch (SQLException e)
{
e.printStackTrace();
System.err.println("N'arrive pas a se connecter a la base !!");
}
return null;
} |