参考: http://cherryqq.iteye.com/blog/353755 http://blog.knowsky.com/259481.htm
1、关闭Connection的自动提交,这在oracle中效果非常明显。
cn.setAutoCommit(false);
2、执行一系列sql语句
要点:执行每一个新的sql语句前,上一次执行sql语句的Statement(或者PreparedStatemet)必须先close
Statement sm ;
sm = cn.createStatement(insert into user...);
sm.executeUpdate();
sm.close();
sm = cn.createStatement("insert into corp...);
sm.executeUpdate();
sm.close();
3、提交
cn.commit();
4、如果发生异常,那么回滚。例如发现插入不完整时候,都应该回滚保证数据的完整性。
cn.rollback();
注意:如果是mysql,则不一定能回滚。