executeBatch() method of Statement interface in JDBC  | JDBC Training

This  JDBC Training “addBatch() method of Statement interface in JDBC” post explains clearly how to execute a batch of sql statements from jdbc application using addBatch() method of Statement interface.


 

addBatch():

  • Pre-defined method of Statement interface.
  • Used to execute a batch of sql statements at a time in JDBC application.

 

Following application includes 4 files:

  1. DB.properties file is used to collect driver loading and connection string details.
  2. DatabaseConnection.java method returns Connection object when required.
  3. Employee.java with setter and getter methods.
  4. AddBatchExample.java to perform operations from JDBC application.

 

 

 

 

Batch method:

  • int[] executeBatch()throws SQLException
    • Submits a batch of commands to the database for execution
    • Returns an array of update counts.

 

Share this