Tiens, vla un p'tit code de base:
//Build the URL to connect...
String urlToConnect = this.buildURL("jdbc", jdbcDriverDesc, dbUrl, dbPort, dbName);
//cat.debug("url of the database:"+urlToConnect);
//Try to init. the connection
try {
//The driver is loaded from the classpath
Class.forName(jdbcDriverClass);
if (dbUser==null || dbPassword==null) {
connection = DriverManager.getConnection(urlToConnect);
}
else {
connection = DriverManager.getConnection(urlToConnect, dbUser, dbPassword);
}
}
catch(SQLException se){
processFatalError("could not find the database", se);
this.isStartable = false;
}
catch(ClassNotFoundException cnf){
processFatalError("could not find the driver for the database", cnf);
this.isStartable = false;
}
Et pour le même prix
, la fonction buildURL() :
private String buildURL(String protocol, String type, String dbUrl, String dbPort, String dbName){
return (protocol+":"+type+"://"+dbUrl+":"+dbPort+"/"+dbName);
}