• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

java.sql.SQLException: Can't call commit when autocommit=true

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting the following exception when i run the below mentioned code.
Can someone please explain why am i getting this exception even though when i i've set relaxAutoCommit=true in Url

java.sql.SQLException: Can't call commit when autocommit=true
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:67)
at com.mysql.cj.jdbc.ConnectionImpl.commit(ConnectionImpl.java:794)
at com.sun.rowset.internal.CachedRowSetWriter.commit(CachedRowSetWriter.java:1405)
at com.sun.rowset.CachedRowSetImpl.acceptChanges(CachedRowSetImpl.java:893)
at com.teja.programs.JdbcApp25_3.main(JdbcApp25_3.java:43)
Exception in thread "main" javax.sql.rowset.spi.SyncProviderException: Can't call commit when autocommit=true
at com.sun.rowset.CachedRowSetImpl.acceptChanges(CachedRowSetImpl.java:912)
at com.teja.programs.JdbcApp25_3.main(JdbcApp25_3.java:43)

 
Saloon Keeper
Posts: 22483
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that actually relaxAutoCommit applies only when talking to really, really old MySQL servers. It's designed to get around the fact that for much of its early life MySQL did not support transactions*. You can't have autoCommit without support for commit, and you cannot support commit without support for transactions.

* Which at the time was a major selling point for PostgreSQL, which did support transactions back then.
 
Saloon Keeper
Posts: 12253
259
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the solution is to create a Connection object with autoCommit false, and pass it to the acceptChanges() method.
    Bookmark Topic Watch Topic
  • New Topic