Batch Processing in JDBC

Instead of executing a single query, we can execute a batch (group) of queries. It makes the performance fast. The java.sql.Statement and java.sql.PreparedStatement interfaces provide methods for batch processing.

Advantage of Batch Processing

Fast Performance

Methods of Statement interface

The required methods for batch processing are given below:

Method

void addBatch(String query)

int[] executeBatch()

Description

It adds query into batch.

It executes the batch of queries.

Example of batch processing in jdbc

Let's see the simple example of batch processing in jdbc. It follows following steps:

  1. Load the driver class
  2. Create Connection
  3. Create Statement
  4. Add query in the batch
  5. Execute Batch
  6. Close Connection

Flash Soon


Example of batch processing using PreparedStatement

Flash Soon



Advertisement

© Sapster 2017