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
| String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://127.0.0.1/mysql ";
String login = "speudo";
String password = "mot de passe";
Connection connec = null;
try
{
// register JDBC driver implementation
Class.forName(driver);
// open connection
connec = DriverManager.getConnection(url,login,password);
}
catch(ClassNotFoundException cnfe)
{
System.err.println("Driver non trouvé");
cnfe.printStackTrace();
}
catch(SQLException sqle)
{
System.err.println("Connexion impossible");
sqle.printStackTrace();
}
finally
{
if (connec != null)
try {connec.close();}
catch (SQLException sqle) {}
} |