여기 내 매우 간단한 테이블 (포스트 그레스)입니다 : 예상대로 나는 데이터베이스에서 아래의 명령을 사용하여 문자열을 삽입하려고하면새로운 행이 삽입되지 않은 경우에도 executeUpdate가 1을 반환하는 이유는 무엇입니까?
CREATE TABLE IF NOT EXISTS PERFORMANCE.TEST
(
test text NOT NULL UNIQUE
);
, 모든 것은 당연한 새 행은 DB에 나타납니다 작품. 내가 JDBC를 통해 문자열을 삽입 할 경우, 아무것도 삽입하지됩니다
insert into performance.test (test) values ('abbbbaw');
, 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);
}
}
}
}
기본적으로 자동 커밋이 true로 설정되어 있으므로 다시 커밋해야합니까? –