From 24d03706e22257ebb6bf42840deb990b59db3aae Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Fri, 26 Jun 2015 23:31:13 +0900 Subject: [PATCH] Add driver.acceptsUrl() check. --- .../com/zaxxer/hikari/util/DriverDataSource.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hikaricp-common/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java b/hikaricp-common/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java index 39af90cf..51a35a0d 100644 --- a/hikaricp-common/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java +++ b/hikaricp-common/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java @@ -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