-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Trond G. Ziarkowski wrote:
> 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?

Trond,

Are your tables in InnoDB storage? (i.e. TYPE=InnoDB used when you
created them)

What does 'SHOW CREAATE TABLE [table-name]' show for both tables?

If it doesn't say 'Type=InnoDB' at the end, transactions won't work :(

        -Mark



- --
Mark Matthews
MySQL AB, Software Development Manager - Client Connectivity
Office: +1 708 332 0507
www.mysql.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBokmYtvXNTca6JD8RApHwAKCh/E83lwfvqMOCEmJTAIzrUDWbogCfVQxL
04L03RNzQvpUg+wNtgLFkSo=
=9qCZ
-----END PGP SIGNATURE-----

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

Reply via email to