1

我想使用 HyperSQL 作为内存数据库来进行 Java - JDBC 应用程序的集成测试。

如果我尝试以下操作:

Properties props = new Properties();
props.put("user", "sa");
props.put("password", "");
Class.forName("org.hsqldb.jdbcDriver");
Connection cn = DriverManager.getConnection("jdbc:hsqldb:mem://localhost", props);

Statement st = cn.createStatement();
st.executeUpdate("Insert into foo (bar) values (10);");

我得到:

java.sql.SQLException: Table not found: foo in statement [Insert into bar]

我认为 HSQL 有一种方法可以在用作内存数据库时动态生成表,但我似乎在文档中找不到它。

4

1 回答 1

2

为什么要执行 INSERT 查询?那不会返回一个ResultSet.

你应该executeUpdate()

HSQL 中没有“自动”的东西。您可能会想到 Hibernate 及其 hbm2ddl。

于 2011-07-14T17:23:43.613 回答