How to rollback series of jdbc transactions in java

695 views Asked by At

My java class will be invoked with a certain number of records(consider 1000) every time. Each time when it got invoked , it needs to insert all the 1000 records into table. Now consider it got invoked three times(means it inserted 3000 records into db in three transactions). Now if any error occurred during third transaction insertion, it needs to rollback all the transactions insertions. Is there any possibility make all three transactions into single transaction(but code receives 1000 records periodically). Please guide me to achieve this scenario.

1

There are 1 answers

2
SJR59 On

You would need a way to keep track of all the insertions during each transaction and then have a function delete them if there is a rollback called. There is no way to easily rollback a transaction after it is committed.