これが私の非常に単純なテーブルです(Postgres):
CREATE TABLE IF NOT EXISTS PERFORMANCE.TEST
(
test text NOT NULL UNIQUE
);
データベースから以下のコマンドを使用して文字列を挿入しようとすると、すべてが期待どおりに機能しますが、驚くことではありませんが、DB に新しい行が表示されます。
insert into performance.test (test) values ('abbbbaw');
ただし、JDBC を介して文字列を挿入したい場合、preparedStatement.executeUpdate() は常に 1 を返しますが、何も挿入されません。
以下は、機能するはずの私の方法ですが、機能しません。明らかな何かが欠けているかどうか教えてください。SQLException が発生しないことを付け加えておきます。
private void storePerformance() {
Connection conn= initializePerformanceConnection();
if (conn!= null) {
PreparedStatement insertPS = null;
try {
insertPS = conn.prepareStatement("insert into performance.test (test) values (?)");
insertPS.setString(1, queryVar);
int i = insertPS.executeUpdate();
LogManager.doLog(LOG, LOGLEVEL.INFO," numberofrows= "+i);
} catch (SQLException e) {
LogManager.doLog(LOG, LOGLEVEL.INFO,"Inserting query failed = "+queryVar,e);
}finally{
if(insertPS != null){
try {
insertPS.close();
} catch (SQLException e) {
LogManager.doLog(LOG, LOGLEVEL.INFO,"Closing PreparedStatement failed = "+queryVar,e);
}
}
try {
conn.close();
} catch (SQLException e) {
LogManager.doLog(LOG, LOGLEVEL.INFO,"Closing performanceConnection failed= "+ queryVar, e);
}
}
}
}