问题描述
H2数据库有list条以SET开头的命令,尤其是SET DB_CLOSE_DELAY。我想找出DB_CLOSE_DELAY的值是什么。我正在使用JDBC。设置很简单
cx.createStatement.execute("SET DB_CLOSE_DELAY 0")
但以下任何一项都不返回DB_CLOSE_DELAY的实际值:
cx.createStatement.executeQuery("DB_CLOSE_DELAY")
cx.createStatement.executeQuery("VALUES(@DB_CLOSE_DELAY)")
cx.createStatement.executeQuery("GET DB_CLOSE_DELAY")
cx.createStatement.executeQuery("SHOW DB_CLOSE_DELAY")
我们将不胜感激。
解决方法
您可以在INFORMATION_SCHEMA.SETTINGS
表中访问此设置和其他设置-例如:
String url = "jdbc:h2:mem:;DB_CLOSE_DELAY=3";
Connection conn = DriverManager.getConnection(url,"sa","the password goes here");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.SETTINGS where name = 'DB_CLOSE_DELAY'");
while (rs.next()) {
System.out.println(rs.getString("name"));
System.out.println(rs.getString("value"));
}
在此测试中,我使用了一个未命名的内存数据库,并且在创建数据库时我将延迟明确设置为3
秒。
print语句的输出为:
DB_CLOSE_DELAY
3