how to make autocommit=false

Discussion in 'Java' started by harryos, Nov 13, 2008.

  1. harryos

    harryos Guest

    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
    harryos, Nov 13, 2008
    #1
    1. Advertising

  2. harryos

    Philipp Guest

    On Nov 13, 10:08 am, harryos <> 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(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
    Philipp, Nov 13, 2008
    #2
    1. Advertising

  3. harryos

    Arne Vajhøj Guest

    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(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
    Arne Vajhøj, Nov 14, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maruda
    Replies:
    1
    Views:
    1,724
    John C. Bollinger
    Dec 31, 2005
  2. Chris

    MySql autocommit off?

    Chris, Jul 15, 2003, in forum: Python
    Replies:
    0
    Views:
    976
    Chris
    Jul 15, 2003
  3. Jia Lu
    Replies:
    2
    Views:
    505
    Jia Lu
    Dec 1, 2006
  4. Paul McNett
    Replies:
    1
    Views:
    358
    Gerhard Häring
    Feb 5, 2008
  5. Christophe Goer

    mod_perl ApacheDBI AutoCommit

    Christophe Goer, Nov 12, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    135
    Christophe Goer
    Nov 12, 2003
Loading...

Share This Page