私は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);
}
}
ここにはコミットはありませんが、自動コミットを実行するように接続が構成されていることに注意してください。