Advertisement
Google Ad Slot: content-top
JDBC Batch Processing
JDBC Batch Processing allows executing multiple SQL statements in a single request, improving performance by reducing the number of database hits.
Performing Multiple Queries in a Batch Processing:
setAutoCommit(false)→ Ensures queries are executed as a single unit.addBatch(sql)→ Adds SQL queries to the batch.executeBatch()→ Executes all queries at once.commit()→ Commits the transaction after successful execution.rollback()→ Rolls back all changes if any error occurs.
Savepoint in a Batch Processing:
Instead of rolling back everything, Savepoints allow rolling back to a specific point.
- It marks a specific point in the transaction.
- If an error occurs after the savepoint, you can roll back to that savepoint instead of rolling back the entire transaction.
- It helps in handling batch updates more efficiently.