-
Notifications
You must be signed in to change notification settings - Fork 1
Batch Processing
There can be requirement where multiple times DML i.e. insert, update or delete operations are needed to be performed with database. In such case hitting database again and again to execute queries might cause database performance bottle neck.
To overcome such problems JDBC API
supports batch processing that allows us to perform related operation all together in one shot. Means similar type of database operations can be clubbed/grouped to form a batch and that batch can be submitted to database as single command. This helps improving database performance. Batch processing can be carried out on DMLs(insert, update, delete) and/or database queries that returns nothing like DDL commands.
Batch processing in Statement
is two step process
- Add related DMLs in a batch, to achieve this
addBatch(String sql)
can be invoked onStatement
object - Execute the batch, to achieve this
executeBatch()
can be invoked onStatement
object
Modifier and Type | Method and Description |
---|---|
void |
addBatch(String sql) Adds the given SQL command to the current list of commands for this Statement object. |
void |
clearBatch() Empties this Statement object's current list of SQL commands. |
int[] |
executeBatch() Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts. |
default long[] |
executeLargeBatch() Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts. |
Batch processing in PreparedStatement
is two step process
- Add set of params to a batch, to achieve this
addBatch()
can be invoked onPreparedStatement
object - Execute the batch, to achieve this
executeBatch()
can be invoked onStatement
type object
Modifier and Type | Method and Description |
---|---|
void |
addBatch() Adds a set of parameters to this PreparedStatement object's batch of commands. |
Copyright © 2017. All rights reserved by Atul Dwivedi
Any query? Mail to: atul.atul16dwivedi@gmail.com
- Introduction to JDBC
- JDBC Drivers
- Performing database operations
- Learn basics of JDBC API
- PreparedStatement interface
- CallableStatement interface
- The MetaDeta(data about data)
- Dealing with large objects