how to make autocommit=false

H

harryos

hi
i am learning to create web app talking to database using
mysql ,tomcat6 in NetBeansIDE.I have a java class that makes a
reservation and calls a connection.commit() .This causes an error like

java.sql.SQLException: Can't call commit when autocommit=true
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:914)
com.mysql.jdbc.Connection.commit(Connection.java:2273)
myapp.Reservations.reservationExist(Reservations.java:387)

Do i need to set autocommit =false in tomcat?I checked the server.xml
from the IDE,but couldn't figure out exactly where i should edit to
make autocommit false.

can someone help?
thanks
harry
 
P

Philipp

hi
i am learning to create web app talking to database using
mysql ,tomcat6 in NetBeansIDE.I have a java class that makes a
reservation and calls a connection.commit() .This causes an error like

java.sql.SQLException: Can't call commit when autocommit=true
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:914)
com.mysql.jdbc.Connection.commit(Connection.java:2273)
myapp.Reservations.reservationExist(Reservations.java:387)

Do i need to set autocommit =false in tomcat?

Either keep autocommit to true and don't call commit. The commit is
automatically called when you call executeUpdate() on your Statement.

Or use:
Connection con = ...;
con.setAutoCommit(false);

HTH
Phil
 
A

Arne Vajhøj

harryos said:
i am learning to create web app talking to database using
mysql ,tomcat6 in NetBeansIDE.I have a java class that makes a
reservation and calls a connection.commit() .This causes an error like

java.sql.SQLException: Can't call commit when autocommit=true
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:914)
com.mysql.jdbc.Connection.commit(Connection.java:2273)
myapp.Reservations.reservationExist(Reservations.java:387)

Do i need to set autocommit =false in tomcat?I checked the server.xml
from the IDE,but couldn't figure out exactly where i should edit to
make autocommit false.

You can either set it on a per connection basis with:

conn.setAutoCommit(false);

in your code or on a connection pool basis in the config with:

<Resource ... defaultAutoCommit="false" ... />

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top