Add driver.acceptsUrl() check.

pull/336/head
Brett Wooldridge 10 years ago
parent 6899e5dc6e
commit 24d03706e2

@ -59,7 +59,7 @@ public final class DriverDataSource implements DataSource
while (drivers.hasMoreElements()) {
Driver d = drivers.nextElement();
if (d.getClass().getName().equals(driverClassName)) {
this.driver = d;
driver = d;
break;
}
}
@ -68,7 +68,7 @@ public final class DriverDataSource implements DataSource
LOGGER.warn("Registered driver with driverClassName={} was not found, trying direct instantiation.", driverClassName);
try {
Class<?> driverClass = this.getClass().getClassLoader().loadClass(driverClassName);
this.driver = (Driver) driverClass.newInstance();
driver = (Driver) driverClass.newInstance();
}
catch (Exception e) {
LOGGER.warn("Could not instantiate instance of driver class {}, trying JDBC URL resolution", driverClassName, e);
@ -76,14 +76,17 @@ public final class DriverDataSource implements DataSource
}
}
if (driver == null) {
try {
try {
if (driver == null) {
driver = DriverManager.getDriver(jdbcUrl);
}
catch (SQLException e) {
throw new RuntimeException("Unable to get driver instance for jdbcUrl=" + jdbcUrl, e);
else if (!driver.acceptsURL(jdbcUrl)) {
throw new RuntimeException("Driver " + driverClassName + " claims to not accept JDBC URL " + jdbcUrl);
}
}
catch (SQLException e) {
throw new RuntimeException("Unable to get driver instance for jdbcUrl=" + jdbcUrl, e);
}
}
@Override

Loading…
Cancel
Save