commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Blashill" <JBlash...@rim.com>
Subject [DbUtils] MySQL rollback problem..
Date Wed, 23 Jun 2004 19:03:35 GMT
Hi,

I noticed a problem recently where autoCommit set to false did not work
as I intended. Here is my code snippet:

        Connection connection = dataSource.getConnection();
        connection.setAutoCommit(false);
        boolean success = false;

        QueryRunner queryRunner = new QueryRunner();
        try
        {
		queryRunner.update(connection, sqlStatement1);
		queryRunner.update(connection, sqlStatement2);
		queryRunner.update(connection, sqlStatement3);
            success = true;
        }
        finally
        {
            if (connection != null)
            {
                if (success)
                {
                    connection.commit();
                }
                else
                {
                    connection.rollback();
                }
                connection.close();
            }
        }

What I expected from this code was that all three sql statements would
be performed as a transaction - that is, if one fails then the other
will no go through either. However, I have observed that even then
connection.rollback() get called in the event of an error. The updates
that may have already succeeded do NOT get undone. In fact, they
appeared in the database regardless of whether connection.commit() was
called. I have done similar things using Postgres 7.4, but now it does
not seem to work with mySQL. Has anyone else experienced this? I am
using MySQL 4.

Thanks for any input you may have,

James

FYI, I am using DBCP to do my connection pooling as well.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message