Advertisement
Guest User

Untitled

a guest
May 29th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. public static void main( String[] args ) throws SQLException, XAException {
  2. OracleXADataSource dataSource1 = new OracleXADataSource();
  3. dataSource1.setURL("jdbc:oracle:thin:@//localhost:1521/XE");
  4. dataSource1.setUser("system");
  5. dataSource1.setPassword("111");
  6.  
  7. OracleXADataSource dataSource2 = new OracleXADataSource();
  8. dataSource2.setURL("jdbc:oracle:thin:@//localhost:1521/XE");
  9. dataSource2.setUser("alex");
  10. dataSource2.setPassword("111");
  11.  
  12. XAConnection xaConnection = dataSource1.getXAConnection();
  13. XAResource res = xaConnection.getXAResource();
  14. Connection connection = xaConnection.getConnection();
  15. FooXid xid1 = new FooXid(1);
  16. res.start(xid1, XAResource.TMNOFLAGS);
  17. connection.createStatement().execute("INSERT INTO TABLE1 VALUES (1)");
  18. res.end(xid1, XAResource.TMSUCCESS);
  19.  
  20. XAConnection xaConnection2 = dataSource2.getXAConnection();
  21. XAResource res2 = xaConnection2.getXAResource();
  22. Connection connection2 = xaConnection2.getConnection();
  23. FooXid xid2 = new FooXid(2);
  24. res2.start(xid2, XAResource.TMNOFLAGS);
  25. connection2.createStatement().execute("INSERT INTO TABLE1 VALUES (2)");
  26. res2.end(xid2, XAResource.TMSUCCESS);
  27.  
  28. int verdict = res.prepare(xid1);
  29. int verdict2 = res2.prepare(xid2);
  30.  
  31. if (verdict == XAResource.XA_OK)
  32. res.commit(xid1, false);//breakpoint1
  33.  
  34. if (verdict2 == XAResource.XA_OK)
  35. res2.commit(xid2, false);//breakpoint2
  36.  
  37. xaConnection.close();
  38. xaConnection2.close();
  39.  
  40. connection.close();
  41. connection2.close();
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement