Here is a distributed commit of 2 phase protocol:
public static void main( String[] args ) throws SQLException, XAException { OracleXADataSource dataSource1 = new OracleXADataSource(); dataSource1.setURL("jdbc:oracle:thin:@//localhost:1521/XE"); dataSource1.setUser("system"); dataSource1.setPassword("111"); OracleXADataSource dataSource2 = new OracleXADataSource(); dataSource2.setURL("jdbc:oracle:thin:@//localhost:1521/XE"); dataSource2.setUser("alex"); dataSource2.setPassword("111"); XAConnection xaConnection = dataSource1.getXAConnection(); XAResource res = xaConnection.getXAResource(); Connection connection = xaConnection.getConnection(); FooXid xid1 = new FooXid(1); res.start(xid1, XAResource.TMNOFLAGS); connection.createStatement().execute("INSERT INTO TABLE1 VALUES (1)"); res.end(xid1, XAResource.TMSUCCESS); XAConnection xaConnection2 = dataSource2.getXAConnection(); XAResource res2 = xaConnection2.getXAResource(); Connection connection2 = xaConnection2.getConnection(); FooXid xid2 = new FooXid(2); res2.start(xid2, XAResource.TMNOFLAGS); connection2.createStatement().execute("INSERT INTO TABLE1 VALUES (2)"); res2.end(xid2, XAResource.TMSUCCESS); int verdict = res.prepare(xid1); int verdict2 = res2.prepare(xid2); if (verdict == XAResource.XA_OK) res.commit(xid1, false);//breakpoint1 if (verdict2 == XAResource.XA_OK) res2.commit(xid2, false);//breakpoint2 xaConnection.close(); xaConnection2.close(); connection.close(); connection2.close(); } When I reach the debager at // breakpoint1 or // breakpoint2 and try to select the SELECT values from the table, the query passes. But the table must be locked according to the documentation!