日期:2014-05-16 浏览次数:20478 次
1. try { 2. 3. conn = 4. 5. DriverManager.getConnection 6. 7. ("jdbc:oracle:thin:@host:1521:SID","username","userpwd"; 8. 9. conn.setAutoCommit(false);//禁止自动提交,设置回滚点 10. 11. stmt = conn.createStatement(); 12. 13. stmt.executeUpdate(“alter table …”); //数据库更新操作1 14. 15. stmt.executeUpdate(“insert into table …”); //数据库更新操作2 16. 17. conn.commit(); //事务提交 18. 19. }catch(Exception ex) { 20. 21. ex.printStackTrace(); 22. 23. try { 24. 25. conn.rollback(); //操作不成功则回滚 26. 27. }catch(Exception e) { 28. 29. e.printStackTrace(); 30. 31. } 32. 33. } try { conn = DriverManager.getConnection ("jdbc:oracle:thin:@host:1521:SID","username","userpwd"; conn.setAutoCommit(false);//禁止自动提交,设置回滚点 stmt = conn.createStatement(); stmt.executeUpdate(“alter table …”); //数据库更新操作1 stmt.executeUpdate(“insert into table …”); //数据库更新操作2 conn.commit(); //事务提交 }catch(Exception ex) { ex.printStackTrace(); try { conn.rollback(); //操作不成功则回滚 }catch(Exception e) { e.printStackTrace(); } }
1. // ... 2. DataSource ds = obtainXADataSource(); 3. Connection conn = ds.getConnection(); 4. pstmt = conn.prepareStatement("UPDATE MOVIES ..."); 5. pstmt.setString(1, "Spinal Tap"); 6. pstmt.executeUpdate(); 7. // ... 8. utx.commit(); // ... DataSource ds = obtainXADataSource(); Connection conn = ds.getConnection(); pstmt = conn.prepareStatement("UPDATE MOVIES ..."); pstmt.setString(1, "Spinal Tap"); pstmt.executeUpdate(); // ... utx.commit();
1. import javax.transaction.xa.*; 2. public class MyXid implemen