1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/configuration/Loader.java Sun May 17 13:15:21 2015 +0200
1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/Loader.java Sun May 17 13:51:40 2015 +0200
1.3 @@ -21,6 +21,7 @@
1.4 import static info.globalcode.sql.dk.DatabaseConnection.JDBC_PROPERTY_USER;
1.5 import static info.globalcode.sql.dk.DatabaseConnection.JDBC_PROPERTY_PASSWORD;
1.6 import java.sql.Connection;
1.7 +import java.sql.Driver;
1.8 import java.sql.DriverManager;
1.9 import java.sql.SQLException;
1.10 import java.util.logging.Level;
1.11 @@ -66,7 +67,22 @@
1.12 credentials.setDefaults(databaseDefinition.getProperties());
1.13 properties.setDefaults(credentials);
1.14 java.util.Properties javaProperties = properties.getJavaProperties();
1.15 - return DriverManager.getConnection(databaseDefinition.getUrl(), javaProperties);
1.16 +
1.17 + String driverClassName = databaseDefinition.getDriver();
1.18 + final String url = databaseDefinition.getUrl();
1.19 + if (driverClassName == null) {
1.20 + log.log(Level.FINE, "Using DriverManager to create connection for „{0}“", url);
1.21 + return DriverManager.getConnection(url, javaProperties);
1.22 + } else {
1.23 + log.log(Level.FINE, "Using custom Driver „{0}“ to create connection for „{1}“", new Object[]{driverClassName, url});
1.24 + try {
1.25 + Class<Driver> driverClass = (Class<Driver>) Class.forName(driverClassName);
1.26 + Driver driver = driverClass.newInstance();
1.27 + return driver.connect(url, javaProperties);
1.28 + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException e) {
1.29 + throw new SQLException("Unable to connect usig specific driver: " + driverClassName, e);
1.30 + }
1.31 + }
1.32 }
1.33
1.34 }