private void initializeDriverManagerConnection(ConnectionInfo connectionInfo) {
Connection connection = null;
if (connectionInfo.getConnectionProperties() == null) {
throw new DataSourceInitializationException("No existing context and no connection properties");
}
if (connectionInfo.getConnectionProperties().getDriverClass() == null) {
throw new DataSourceInitializationException("No jdbc driver class specified!");
}
try {
//initialize driver and register it with DriverManager
Class.forName(connectionInfo.getConnectionProperties().getDriverClass());
//prepare to initialize connection
String databaseUrl = connectionInfo.getConnectionProperties().getDatabaseURL();
String userName = connectionInfo.getConnectionProperties().getUserName();
String userPassword = connectionInfo.getConnectionProperties().getPassword();
int loginTimeout = connectionInfo.getConnectionProperties().getLoginTimeout();
DriverManager.setLoginTimeout(loginTimeout);
if( (userName == null || userName.length() ==0) && (userPassword == null || userPassword.length()==0) ){
//no username or password suplied
connection = DriverManager.getConnection(databaseUrl);
}else{
connection = DriverManager.getConnection(databaseUrl, userName, userPassword);
}
if(connection == null){
throw new DataSourceInitializationException("Error initializing connection : null");
}
connection.setAutoCommit(false);
setConnection(connection);
}catch(ClassNotFoundException cnf){
throw new DataSourceInitializationException("JDBC Driver '" + connectionInfo.getConnectionProperties().getDriverClass() + "' not found", cnf);
}catch(SQLException sqle){
throw new DataSourceInitializationException(sqle.getMessage(), sqle);
}
}