java - SQL batch update - rollback on "CREATE TABLE"? -
i have method upgrading db:
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 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 no errors, commit conn.commit(); st.close(); conn.close(); } and upgrade method:
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 project(titlea) values('test1')"); } an error in insert testing rollback.
well, problem not rollbacks create table project. table innodb. suggestions?
this not supported mysql/innodb. ddl statements (create table, alter table, create index, drop ...) happen outside of transaction control.
this weak point iirc postgres can handle better, mysql have work around reverting changes in case of rollbacks.
Comments
Post a Comment