Have you taken care that Auto-commit is set to false? Sometimes we tend to forget the little things you know. Even after we set it to false, there are scenarios that complete rollback can fail in. For example, let's say there's a exception and we don't rollback the transaction in the exception handler.
marc balum
Greenhorn
Joined: Sep 25, 2008
Posts: 7
posted
0
Hi,
Here is my code:
[added code tags - Dave] [ September 27, 2008: Message edited by: David O'Meara ]
tapeshwar sharma
Ranch Hand
Joined: Mar 10, 2006
Posts: 245
posted
0
Hi, my 2 cents: 1) Kindly check the DB and the Driver that you are using. It could be that the driver does not support Batch updates. 2) You may want to change the exception handling to include BatchUpdateException.
marc balum
Greenhorn
Joined: Sep 25, 2008
Posts: 7
posted
0
Hi,
I'm using MySQL ODBC 3.51 Driver.
I tried using createStatement() instead of PreparedStatement, and it was working properly. The sql statements are executed as one transaction when I used the createStatement. But the requirement is I need to use the PreparedStatement to execute a group of sql statements as one transaction. This is because PreparedStatements are safe from sql injection attacks.
I am already using MySQL JDBC driver now. It's the mysql-connector-java-5.1.6 I'm testing now for the preparedStatements above. But, it is still not working as it should be. The preparedStatements are still not committed as a single transaction. They are committed sequentially wherein when one sql statement fails, the sql statements before it are not rolled back. Are there specific database properties to be set for the driver to be able to treat a group of sql statements as a single transaction?