smeacham

JDBC Transaction with Rollback example

Sep 18th, 2012
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.37 KB | None | 0 0
  1. boolean autoCommitDefault = conn.getAutoCommit();
  2. try {
  3.     conn.setAutoCommit(false);
  4.  
  5.     /* You execute statements against conn here transactionally */
  6.  
  7.     conn.commit();
  8. } catch (Throwable e) {
  9.     try { conn.rollback(); } catch (Throwable ignore) {}
  10.     throw e;
  11. } finally {
  12.     try { conn.setAutoCommit(autoCommitDefault); } catch (Throwable ignore) {}
  13. }
Advertisement
Add Comment
Please, Sign In to add comment