This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Transfer Learning for Natural Language Processing (MEAP) and have Paul Azunre on-line!
See this thread for details.
Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

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: 21960
149
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: 11881
253
  • 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.
 
Die Fledermaus does not fear such a tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic