JDBC Tutorial

JDBC JDBC Bulk Updates

        JDBC Batch Updates,sending bunch of SQL statements as a batch to the Database. Otherwise sending Multiple SQL statements to the Database implies multiple calls to the Database. JDBC Batch Updates avoids this round trips, submits Batch of SQL statements as whole to the Database or as a Unit. Each SQL statement gets updatecount. Based on Updatecount, the programmer can identify SQL statement's success or Failure.

Batch Update methods in Statement or PreparedStatement Interfaces


addBatch method

       addBatch methods adds SQL statements to statement Object or PreparedStatement Object. Only DML Operations are permitted in batch Updates. It can be INSERT,UPDATE or DELETE operations.

executeBatch method

       executeBatch methods Executes/submits all SQL statements previously added to statement Object or PreparedStatement. Returns int array ,each array element has status of DML operations submitted. 0 means success, 1 means failure. In failure BatchUpdateException will be thrown, it has failure details.

Exception Class in Batch Update: BatchUpdateException