Batch processing in JDBC applications
Instead of updating one row at a time, we can also update multiple rows simultaneously. We can create a batch from a set of statements and execute them at once. This is mainly done for better performance, as compared to updating a single row at a time. We can only create a batch for similar update statements (also known as batch-compatible statements). All statements must have similar types of input parameters. Either all statements should have input parameters or none of them should have input parameters.
Getting ready
A batch update can be done by using the following methods on the PreparedStatement
object.
addBatch()
executeBatch()
clearBatch()
How to do it...
A batch can be created for a Statement
object or a PreparedStatement
object. If we want to execute multiple SQL statements as part of a batch, then we need to create a batch for a Statement
object. If we want to execute a single SQL statement with different values for the parameter markets...