Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8491911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:34:04+00:00 2026-06-10T22:34:04+00:00

I use sqlite database and java.sql classes in servlet application to batch-insert some data

  • 0

I use sqlite database and java.sql classes in servlet application to batch-insert some data into database.
There are consecutive four inserts of different kinds of data.
Each one looks like this:

PreparedStatement statement = conn
    .prepareStatement("insert or ignore into nodes(name,jid,available,reachable,responsive) values(?,?,?,?,?);");
for (NodeInfo n : nodes)
{
    statement.setString(1, n.name);
    statement.setString(2, n.jid);
    statement.setBoolean(3, n.available);
    statement.setBoolean(4, n.reachable);
    statement.setBoolean(5, n.responsive);
    statement.addBatch();
}

conn.setAutoCommit(false);
statement.executeBatch();
conn.commit();
conn.setAutoCommit(true);
statement.close();

But sometimes I get the

java.sql.SQLException: database in auto-commit mode

I found in source code of java.sql.Connection that this exception is thrown when calling commit() while database is in autocommit mode. But I turn autocommit off before and I can’t see any place for some parallel execution related issues as for now application is only turned on once.

Do you have any idea how to debug this issue? Maybe there’s some other reason for this error (because I just found that exception about database not found or not well configured can be thrown when inserting null into non-null field)?.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:34:06+00:00Added an answer on June 10, 2026 at 10:34 pm

    May be an issue is with order of statements. Your database statement should be :

      PreparedStatement statement1 = null;
      PreparedStatement statement2 = null;
      Connection connection=null;
    
        try {
            //1. Obtain connection and set `false` to autoCommit
            connection.setAutoCommit(false);
            //2. Prepare and execute statements
            statement1=connection.prepareStatement(sql1);
            statement2=connection.prepareStatement(sql2);
            ...
            //3. Execute the statements
    
            statement1.executeUpdate();
            statement2.executeUpdate();
    
            //4. Commit the changes
    
            connection.commit();
            }
        } catch (SQLException e ) {
            if (connection!=null) {
                try {
                    connection.rollback();
                } catch(SQLException excep) {}
            }
        }finally {
            if (statement1 != null) {
                statement1.close();
            }
            if (statement2 != null) {
                statement2.close();
            }
           if(connection != null){
              connection.setAutoCommit(true);
              connection.close();
            }
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to use SQLite for some database functionality with a Java program
I have an application of which i have use database to insert values on
I know that on Android there is android.database.sqlite package that provides helpful classes to
I have written a java application that sporadically logs events to an SQLite database
I use a SQLite Database and a Java GUI. The information entered on the
I'm using a background thread to read from a Sqlite database some GPS data...and
to prevent user inputs the same data into database i use this db.execSQL(CREATE UNIQUE
I'm working on a program using a SQL database (I use SQLite). What my
Hi i am developing android application, And now i have to use sqlite database
I'm developing from Mac OS X a java application that uses a SQLite database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.