提交 790a5ccd authored 作者: Thomas Mueller's avatar Thomas Mueller

Database-level connection settings could only be set in the database URL, but…

Database-level connection settings could only be set in the database URL, but not using the Properties parameter of DriverManaget.getConnection(String url, Properties info).
上级 25ab44fc
...@@ -188,13 +188,22 @@ public class ConnectionInfo implements Cloneable { ...@@ -188,13 +188,22 @@ public class ConnectionInfo implements Cloneable {
private void readProperties(Properties info) { private void readProperties(Properties info) {
Object[] list = new Object[info.size()]; Object[] list = new Object[info.size()];
info.keySet().toArray(list); info.keySet().toArray(list);
DbSettings s = null;
for (Object k : list) { for (Object k : list) {
String key = StringUtils.toUpperEnglish(k.toString()); String key = StringUtils.toUpperEnglish(k.toString());
if (prop.containsKey(key)) { if (prop.containsKey(key)) {
throw DbException.get(ErrorCode.DUPLICATE_PROPERTY_1, key); throw DbException.get(ErrorCode.DUPLICATE_PROPERTY_1, key);
} }
Object value = info.get(k);
if (isKnownSetting(key)) { if (isKnownSetting(key)) {
prop.put(key, info.get(k)); prop.put(key, value);
} else {
if (s == null) {
s = getDbSettings();
}
if (s.containsKey(key)) {
prop.put(key, value);
}
} }
} }
} }
......
...@@ -6,8 +6,11 @@ ...@@ -6,8 +6,11 @@
*/ */
package org.h2.test.jdbc; package org.h2.test.jdbc;
import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Properties;
import org.h2.Driver; import org.h2.Driver;
import org.h2.test.TestBase; import org.h2.test.TestBase;
...@@ -27,6 +30,27 @@ public class TestDriver extends TestBase { ...@@ -27,6 +30,27 @@ public class TestDriver extends TestBase {
} }
public void test() throws Exception { public void test() throws Exception {
testSettingsAsProperties();
testDriverObject();
}
private void testSettingsAsProperties() throws Exception {
Properties props = new Properties();
props.put("user", getUser());
props.put("password", getPassword());
props.put("max_compact_time", "1234");
props.put("unknown", "1234");
String url = getURL("driver", true);
Connection conn = DriverManager.getConnection(url, props);
ResultSet rs;
rs = conn.createStatement().executeQuery(
"select * from information_schema.settings where name='MAX_COMPACT_TIME'");
rs.next();
assertEquals(1234, rs.getInt(2));
conn.close();
}
private void testDriverObject() throws Exception {
Driver instance = Driver.load(); Driver instance = Driver.load();
assertTrue(DriverManager.getDriver("jdbc:h2:~/test") == instance); assertTrue(DriverManager.getDriver("jdbc:h2:~/test") == instance);
Driver.unload(); Driver.unload();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论