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

When you work with JDBC application, by default the auto commit is set to true, after the transaction is completed all the transactions are committed to the database. When it is set as true, you can not explicitly call the commit method. If you call the connection.commit() method, then the below exception will be thrown.

INFO: Loaded JDBC driver: com.mysql.jdbc.Driver
Exception in thread "main" java.lang.RuntimeException: java.sql.SQLException: Can't call commit when autocommit=true
	at javabeat.net.spring.core.Country.insertCountryName(Country.java:54)
	at javabeat.net.spring.core.SpringStandAloneExample.main(SpringStandAloneExample.java:11)
Caused by: java.sql.SQLException: Can't call commit when autocommit=true
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:914)
	at com.mysql.jdbc.Connection.commit(Connection.java:2275)
	at javabeat.net.spring.core.Country.insertCountryName(Country.java:51)

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*