Java 如何使用HSQLDB为JDBC应用程序动态生成表

Java 如何使用HSQLDB为JDBC应用程序动态生成表,java,jdbc,integration-testing,hsqldb,in-memory-database,Java,Jdbc,Integration Testing,Hsqldb,In Memory Database,我想将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

我想将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在用作内存数据库时可以动态生成表,但在文档中似乎找不到它。

为什么要执行INSERT查询?不会返回
结果集

您应该
executeUpdate()


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

哎呀,在实验中遇到了麻烦。已编辑。您的数据库中是否已有
foo
?如果它还不存在,它怎么知道它的模式呢?