the following sample program uses jta methods to execute distributed transactions, but in the rollback method it is not working properly.Can anybody give suggestions / Solutions would be greatful..
try
{
stmt1 = con1.createStatement();
xaRes1.start(xid1, XAResource.TMNOFLAGS);
stmt1.executeUpdate("insert into company (empNumber,name,jobtitle) values ('1028','hayden','developer')");
xaRes1.end(xid1, XAResource.TMSUCCESS);
System.out.println("Data inserted successfully into Company");
ret1 = xaRes1.prepare(xid1);
if (ret1 == XAResource.XA_OK)
{
xaRes1.commit(xid1, false);
}
stmt2 = con2.createStatement();
xaRes2.start(xid2, XAResource.TMNOFLAGS);
stmt2.executeUpdate("insert into maincompany (empNumber,name,jobtitle,branch) values ('1016','Hussey','developer','England')");
xaRes2.end(xid2, XAResource.TMSUCCESS);
System.out.println("Data inserted successfully into Main company");
ret2 = xaRes2.prepare(xid2);
if (ret2 == XAResource.XA_OK)
{
xaRes2.commit(xid2, false);
}
}
catch (com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException e)
{
//Distributed transaction failed, so roll it back.
// Report XAException on prepare/commit.
System.out.println("Distributed transaction prepare/commit failed. " +
"Rolling it back.");
System.out.println("XAException error code = " + e.getErrorCode());
System.out.println("XAException message = " + e.getMessage());
e.printStackTrace();
try
{
xaRes1.rollback(xid1);
}
catch (javax.transaction.xa.XAException e1)
{ // Report failure of rollback.
System.out.println("distributed Transaction rollback xares1 failed");
System.out.println("XAException message = " + e1.getMessage());
}
try
{
xaRes2.rollback(xid2);
}
catch (javax.transaction.xa.XAException e2)
{ // Report failure of rollback.
System.out.println("distributed Transaction rollback xares2 failed");
System.out.println("XAException message = " + e2.getMessage());
}
}
//closing of connections between the database
stmt1.close();
con1.close();
xaCon1.close();
stmt2.close();
con2.close();
xaCon2.close();
}
}
-
Error in rollbacking the transaction using jta (1 messages)
- Posted by: Balaji Ramanujam
- Posted on: April 19 2010 14:34 EDT
Threaded Messages (1)
- Error in rollbacking the transaction using jta by Jeryl Cook on April 22 2010 13:22 EDT
-
Error in rollbacking the transaction using jta[ Go to top ]
- Posted by: Jeryl Cook
- Posted on: April 22 2010 13:22 EDT
- in response to Balaji Ramanujam
What do you mean not working specifically?I strongly recommend you use Spring JTA and a J2EE Application Server( global transaction via JNDI) for multiple data sources.RE:Jeryl Cook