Hi all!

In my webapp I do two db inserts into two different tables. If the second one fails I want to rollback the first one. My code is something like the following:

Connection con = gotten from jndi DataSource
DBBean db = new DBBean(con);
try {
   con.setAutoCommit(false);

   Object o = db.getSomething();
   Object o2 = db.getSomethingElse();

   db.doInsert1(params);
   db.doInsert2(params);

   con.commit();
} catch (SQLException sqle) {
   con.rollback();
   throw sqle;
} finally {
   if (con != null) {
       con.close();
   }
}

I thought that this should do the trick, but if the second insert fails the data inserted in the first insert are still there. I am using MySQL 4.0.21-7 with InnoDB and have tested that I can use transactions with the MySQL client.

Anyone got any tips?


Regards

Trond

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to