提交 d3bb6c84 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Detect unsupported URLs for the driver in JdbcUtils.getConnection()

上级 1fc1d43e
......@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>Issue #1730: console can no longer connect to psql dbs in v1.4.197 (works in v1.4.196)
</li>
<li>Issue #1590: Error on executing "DELETE FROM table1 WHERE ID = ?; DELETE FROM table2 WHERE ID = ?;"
</li>
<li>Issue #1727: Support ISODOW as identifier for the extract function additional to ISO_DAY_OF_WEEK
......
......@@ -288,17 +288,24 @@ public class JdbcUtils {
JdbcUtils.load(url);
} else {
Class<?> d = loadUserClass(driver);
if (java.sql.Driver.class.isAssignableFrom(d)) {
try {
try {
if (java.sql.Driver.class.isAssignableFrom(d)) {
Driver driverInstance = (Driver) d.getDeclaredConstructor().newInstance();
return driverInstance.connect(url, prop); /*fix issue #695 with drivers with the same
jdbc subprotocol in classpath of jdbc drivers (as example redshift and postgresql drivers)*/
} catch (Exception e) {
throw DbException.toSQLException(e);
}
} else if (javax.naming.Context.class.isAssignableFrom(d)) {
// JNDI context
try {
/*
* fix issue #695 with drivers with the same jdbc
* subprotocol in classpath of jdbc drivers (as example
* redshift and postgresql drivers)
*/
Connection connection = driverInstance.connect(url, prop);
if (connection != null) {
return connection;
}
/*
* URL is not valid for the specified driver, fallback to
* default.
*/
} else if (javax.naming.Context.class.isAssignableFrom(d)) {
// JNDI context
Context context = (Context) d.getDeclaredConstructor().newInstance();
DataSource ds = (DataSource) context.lookup(url);
String user = prop.getProperty("user");
......@@ -307,13 +314,11 @@ public class JdbcUtils {
return ds.getConnection();
}
return ds.getConnection(user, password);
} catch (Exception e) {
throw DbException.toSQLException(e);
}
} else {
// don't know, but maybe it loaded a JDBC Driver
return DriverManager.getConnection(url, prop);
} catch (Exception e) {
throw DbException.toSQLException(e);
}
// don't know, but maybe it loaded a JDBC Driver
}
return DriverManager.getConnection(url, prop);
}
......
......@@ -510,12 +510,15 @@ public class TestTools extends TestDb {
}
private void testJdbcDriverUtils() {
assertEquals("org.h2.Driver",
JdbcUtils.getDriver("jdbc:h2:~/test"));
assertEquals("org.postgresql.Driver",
JdbcUtils.getDriver("jdbc:postgresql:test"));
assertEquals(null,
JdbcUtils.getDriver("jdbc:unknown:test"));
assertEquals("org.h2.Driver", JdbcUtils.getDriver("jdbc:h2:~/test"));
assertEquals("org.postgresql.Driver", JdbcUtils.getDriver("jdbc:postgresql:test"));
assertEquals(null, JdbcUtils.getDriver("jdbc:unknown:test"));
try {
JdbcUtils.getConnection("org.h2.Driver", "jdbc:h2x:test", "sa", "");
fail("Expected SQLException: No suitable driver found");
} catch (SQLException e) {
// OK
}
}
private void testWrongServer() throws Exception {
......
......@@ -807,4 +807,4 @@ analyst occupation distributive josaph aor engineer sajeewa isuru randil kevin d
corrupts splitted disruption unintentional octets preconditions predicates subq objectweb insn opcodes
preserves masking holder unboxing avert iae transformed subtle reevaluate exclusions subclause ftbl rgr
presorted inclusion contexts aax mwd percentile cont interpolate mwa hypothetical regproc childed listagg foreground
isodow isoyear
isodow isoyear psql
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论