File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Cannot invoke a rollback operation when the AutoCommit mode is set to Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Cannot invoke a rollback operation when the AutoCommit mode is set to "true"" Watch "Cannot invoke a rollback operation when the AutoCommit mode is set to "true"" New topic
Author

Cannot invoke a rollback operation when the AutoCommit mode is set to "true"

Arpit Aggarwal
Greenhorn

Joined: Feb 11, 2010
Posts: 4
I am using ScriptRunner class For running SQL scripts For SQL SERVER 2005 Data base. It is giving me following error for insertion queries other queries for deletion or selection is working fine.

com.microsoft.sqlserver.jdbc.SQLServerException: Cannot invoke a rollback operation when the AutoCommit mode is set to "true".
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.rollback(Unknown Source)
at com.ibatis.common.jdbc.ScriptRunner.runScript(ScriptRunner.java:222)
at com.ibatis.common.jdbc.ScriptRunner.runScript(ScriptRunner.java:114)

Please help what can be the issue.

Thanks

Arpit
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32611
    
    4
Of course you can't rollback when autocommit is on. If you need rollback, you must turn autocommit off. Or use a transaction, which is a posh way of turning autocommit off.
Arpit Aggarwal
Greenhorn

Joined: Feb 11, 2010
Posts: 4
Thanks Campbell, I tried with some <prop key="hibernate.connection.autocommit">false</prop> for doing auto commit false from my spring application context file. As well as tried to off auto commit of Database SQL SERVER 2005 by using command SET IMPLICIT_TRANSACTIONS { ON } but it is giving same error to me.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Arpit Aggarwal wrote:Thanks Campbell, I tried with some <prop key="hibernate.connection.autocommit">false</prop> for doing auto commit false from my spring application context file. As well as tried to off auto commit of Database SQL SERVER 2005 by using command SET IMPLICIT_TRANSACTIONS { ON } but it is giving same error to me.


Don't you pass the autocommit property as a parameter in ScriptRunner's constructor?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Arpit Aggarwal
Greenhorn

Joined: Feb 11, 2010
Posts: 4
Thanks Paul, I was pasing wrong parameter in ScriptRunner's constructor once i changed:

scriptRunner = new ScriptRunner(con, true, true);

To

scriptRunner = new ScriptRunner(con, false, true);

Its working fine for me

Thanks a lot for your help Paul, Campbell.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You are welcome
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32611
    
    4
Paul Sturrock wrote:You are welcome
Agreed
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot invoke a rollback operation when the AutoCommit mode is set to "true"
 
Similar Threads
Can I call a stored proc without wrapping it in a transaction?
PreparedStatement not throwing error when it should
Error connecting to MSSQL Server from Hibernate
Does a Connection commit on close?
Auto commit???