我对 H2 DB 有点陌生,从我在几个示例和官方文档中看到的内容来看,我设法启动了连接并将值插入到 DB 中。现在,DELETE 命令每次都给我一个 COLUMN NOT FOUND 错误 [42122] 并且条目没有被删除。此错误仅在使用条件 DELETE 语句时发生,而不是在从表中删除所有条目时发生。
该表创建如下
CREATE TABLE SCHEDULE(NAME VARCHAR(40), NUMBER INT);
我的Java代码如下
try {
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
System.out.println("CONNECTED");
Statement stat = conn.createStatement();
if (remember_entry.isSelected()) {
String add_entry = "INSERT INTO SCHEDULE VALUES ('" + name + "'," + number + ")";
System.out.println(add_entry);
stat.execute(add_entry);
System.out.println("ENTRY ADDED");
} else if (!remember_entry.isSelected()) {
String remove_entry = "DELETE FROM SCHEDULE WHERE NAME = '" + name + "' AND number = " + number;
System.out.println(remove_entry);
stat.execute(remove_entry);
System.out.println("ENTRY REMOVED");
}
conn.close();
} catch (Exception e) {
System.out.println(e);
}