Batching Requests

Issuing multiple INSERT or UPDATE statements against a database can be very inefficient, especially if the client is on a remote network. Each time the executeUpdate() method is called, the SQL is sent to the database engine and is processed, and then results are returned to the application. This process is repeated until all of the rows are inserted, deleted, or updated.

JDBC includes the addBatch(), clearBatch(), and executeBatch() methods to improve the efficiency of sending multiple SQL requests to the database engine. These batch methods are summarized in the following list.

  • void addBatch(String sql)— This method allows a programmer to batch a number of statements together in one call to the database. To reduce the overhead ...

Get Apache Derby—Off to the Races: Includes Details of IBM® Cloudscape™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.