我正在使用 HSQLDB。在 java 函数中,我正在创建一个临时表并用一些数据填充它。在我使用临时表中的数据更新常规表之后。
如果我调试函数内部的代码并执行,SELECT
我可以看到两个表中的数据确实已更新,但在提交更改后,表不再更新!(常规表,而不是临时表)。
当我创建我使用的临时表时:ON COMMIT PRESERVE ROWS
但它没有帮助。
有谁知道为什么会这样?
谢谢!
这是代码:
public synchronized void foo(String[] objectsToMark) throws Exception {
String createTempTableQuery = "CREATE TEMP TABLE "+TEMP_TABLE_NAME+"(OBJECTID VARCHAR) " +
"ON COMMIT PRESERVE ROWS";
String dropTempTableQuery = "DROP TABLE "+TEMP_TABLE_NAME;
String updateQueryString = "update " + TABlE_A + " set " +TABlE_A+".X = 'N' where "+TABlE_A+".RESULT_ID in (select "+TABlE_A+".RESULT_ID FROM "+TABlE_A
+" inner join "+TABLE_B+" on "+TABLE_B+".OBJECTID = "+TABlE_A+".OBJECTID"
+" inner join TEMP_TABLE on "+TABLE_B+".OBJECTID = TEMP_TABLE.OBJECTID"
+" where "+TABlE_A+".IS_X = 'Y')";
String insertObjectIDs = "INSERT INTO " + TEMP_TABLE_NAME + " (OBJECTID) VALUES (?)";
Connection conn = null;
Statement stmt = null;
PreparedStatement psInsertObjectIDs = null;
try {
conn = getConnection(getClass().getName() + "");
stmt = conn.createStatement();
stmt.execute(createTempTableQuery);
// insert object's IDs into table
psInsertObjectIDs = conn.prepareStatement(insertObjectIDs);
for (String id : objectsToMark) {
int i = 0;
psInsertObjectIDs.setString(++i, id);
psInsertObjectIDs.addBatch();
}
psInsertObjectIDs.executeBatch();
stmt.execute(updateQueryString);
} catch (Exception e) {
} finally {
// close resources
close(stmt);
stmt = null;
// drop the temporary tables
if (conn != null) {
try {
stmt = conn.createStatement();
stmt.execute(dropTempTableQuery);
} catch (SQLException e) {
}
close(stmt);
}
close(psInsertObjectIDs);
closeConnection(conn);
}
}
请注意,这里没有提交,但连接被配置为执行自动提交。