[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
could any body tell me how to manage transactions using jdbc. Please find the details below.
I want to insert 100 rows in a table and at 51 row an exception is thrown. in this case what exactly happens to the transaction.
how can i ensure that all the 50 rows, which are already inserted are saved in the table.
Any help would be highly appreciated.
i suppose that each insertion is a single transaction and on successful insertion that would be committed. we can make all 100 records insertion as a single transaction by making the whole job as a batch job.
Or you can try locking the tables involved, inserting all the updates, then commit and unlock the tables.
That doesn't sound quite right. It may be the way you are expressing it, but if you have a batch of 100 transactions, then 99 of them will be executed and no 51 will be rolled back. If you want a single transaction you would have to put all 100 updates into the same transaction. I don't know whether you can nest transactions inside transactions, but "nested transactions" sounds very peculiar.Balu Sadhasivam wrote:
i suppose that each insertion is a single transaction and on successful insertion that would be committed. we can make all 100 records insertion as a single transaction by making the whole job as a batch job.
Yes you are right.
Sorry, I wasn't clear. I meant that as an alternative to using a transaction.Or you can try locking the tables involved, inserting all the updates, then commit and unlock the tables.
That doesn't sound quite right. It may be the way you are expressing it, but if you have a batch of 100 transactions, then 99 of them will be executed and no 51 will be rolled back. If you want a single transaction you would have to put all 100 updates into the same transaction
Sorry, I wasn't clear. I meant that as an alternative to using a transaction.