jdbc savepoint代码片段

来源:互联网 发布:2017欧文总决赛数据 编辑:程序博客网 时间:2024/04/29 09:10

conn.setAutoCommit(false);  

 // Set a conservative transaction isolation level.   

conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);   

Statement stmt = conn.createStatement();   

int rows = stmt.executeUpdate( "INSERT INTO authors " +   " (first_name, last_name) VALUES " +   " ('Ghq', 'Wxl')");   // Set a named savepoint.  

 Savepoint svpt = conn.setSavepoint("NewAuthor");   // …  

 rows = stmt.executeUpdate( "UPDATE authors set type = 'fiction' " +   "WHERE last_name = 'Wxl'");   // …   

conn.rollback(svpt);   // …   // The author has been added, but not updated.   

conn.commit();

原创粉丝点击