Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how to make autocommit=false

Reply
Thread Tools

how to make autocommit=false

 
 
harryos
Guest
Posts: n/a
 
      11-13-2008
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(SQLErro r.java:914)
com.mysql.jdbc.Connection.commit(Connection.java:2 273)
myapp.Reservations.reservationExist(Reservations.j ava: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
 
Reply With Quote
 
 
 
 
Philipp
Guest
Posts: n/a
 
      11-13-2008
On Nov 13, 10:08*am, harryos <(E-Mail Removed)> wrote:
> 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(SQLErro r.java:914)
> com.mysql.jdbc.Connection.commit(Connection.java:2 273)
> myapp.Reservations.reservationExist(Reservations.j ava: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
 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      11-14-2008
harryos wrote:
> 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(SQLErro r.java:914)
> com.mysql.jdbc.Connection.commit(Connection.java:2 273)
> myapp.Reservations.reservationExist(Reservations.j ava: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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to test python extension modules during 'make check' / 'make distcheck'? Mark Asbach Python 1 11-03-2006 02:29 AM
How does one make use of sub files to make DVD? Bun Mui DVD Video 0 05-21-2006 03:24 PM
How does one make use of sub files to make DVD? Bun Mui Computer Support 0 05-21-2006 03:09 PM
Anyone know how to make XP make a sound when typing? Like old dumb terminals? Fire Computer Support 6 02-17-2004 12:56 AM



Advertisments