0
내가 DB를 업그레이드하는 방법이 있습니다SQL 배치 업데이트 - "CREATE TABLE"에서 롤백 하시겠습니까?
private void executeUpdateBatch(String... sql) throws SQLException {
JdbcConnection connJbdc = new JdbcConnectionImpl();
Connection conn = connJbdc.getConnection();
conn.setAutoCommit(false);
Statement st = conn.createStatement();
for(String s : sql) {
st.addBatch(s);
}
try {
// execute the batch
int[] updateCounts = st.executeBatch();
} catch (BatchUpdateException e) {
int[] updateCounts = e.getUpdateCounts();
checkUpdateCounts(updateCounts);
try {
conn.rollback();
} catch (Exception e2) {
}
throw new SQLException(e);
}
// since there were no errors, commit
conn.commit();
st.close();
conn.close();
}
을 그리고 업그레이드 방법 :
public void upgradeTo5() throws SQLException {
executeUpdateBatch("CREATE TABLE project ("
+ "id INT(10) unsigned NOT NULL auto_increment, "
+ "title VARCHAR(255) NOT NULL, "
+ "date_from DATE NULL, date_to DATE NULL,"
+ "active BIT NOT NULL, PRIMARY KEY (id))",
"INSERT INTO project(titlea) VALUES('test1')");
}
오류가 바로 테스트 롤백 INSERT
입니다.
글쎄, 이제 문제는 롤백하지 않는다는 것입니다. CREATE TABLE project
. 테이블은 InnoDB이다. 어떤 제안?