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

  • Home
  • SEARCH
  • 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 8164119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:14:40+00:00 2026-06-06T19:14:40+00:00

Next to the addBatch() method of PreparedStatement there is also an addBatch(String) method in

  • 0

Next to the addBatch() method of PreparedStatement there is also an addBatch(String) method in the Statement class.

I want to process a series of different sql statements and am looking for some clarification on what addBatch(String) means performance-wise. Is it safe (and fast) to use this method or is it better to group similar sql-statements in Java and execute them in groups?

  • 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-06T19:14:42+00:00Added an answer on June 6, 2026 at 7:14 pm

    Batch Processing allows you to group related SQL statements into a batch and submit them with one call to the database.

    When you send several SQL statements to the database at once, you reduce the amount of communication overhead, resulting in improving performance.

    addBatch(String sql) is defined in the interface java.sql.Statement and addBatch() is defined in the java.sql.PreparedStatement is one of the subinterface which extends Statement. (Other is java.sql.CallableStatement)

    According to JAVA Doc

    addbatch(String sql) method cannot be called on a PreparedStatement or CallableStatement and sql – typically this is a SQL INSERT or UPDATE statement.

    addBatch() is preferred If you want bulk insertion or bulk update operations.

    There are few blocking factors on batch exections which are

    DB make/version.
    JDBC driver make/version.
    

    For Example: If you’re using MySQL, use the latest driver add rewriteBatchedStatements=true to your connection string to make statement.addBatch() actually create batch inserts.

    Also, You should make sure that auto commit is false. Maintain a counter which and reaching on that counter executeBatch which help when Available heap memory in Java is constraint.

    Example:

    conn.setAutoCommit(false);  
    PreparedStatement pStmt = conn.prepareStatement("INSERT INTO mytable (field1,field2) VALUES (?,?)");
    
    for all values:
      pStmt.setString(1,val1);
      pStmt.setString(2,val2);
      pStmt.addBatch();    
      if ( i % 1000 == 0) {  
                pstmt.executeBatch();// Execute every 1000 items  
      } 
    pstmt.executeBatch(); 
    conn.commit(); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The next code public class FilterState<T>{ Map<String, Object> getProperties(){return null;} // null for shorteness
Next to file menu i want to add a search menu that will have
The next method of java.util.Random , when I view source in Eclipse, is essentially:
Why next code returns true (Saxon-EE 9.2 for .NET)? matches('some text>', '^[\w ]{3,200}$') There
Next year there will be Android programming classes on Wroclaw University (Poland) but handsets
the next is my code: class foo: def __init__(self): self.a = a def __getattr__(self,x,defalut):
the next is my code: class a: w={} def __setattr__(self,name,value): self.w[name]=value def __getattr__(self,name): return
next_permutation is a C++ function which gives the lexicographically next permutation of a string.
The next part of the assignment tells me that the Class RacingCar contains four
I have next code: class iCache<K,V> implements Map<Object, Object> { ...//Code } How can

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.