aspose file tools
The moose likes JDBC and the fly likes what if jdbc commit throws exception in a loop ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "what if jdbc commit throws exception in a loop ?" Watch "what if jdbc commit throws exception in a loop ?" New topic
Author

what if jdbc commit throws exception in a loop ?

Csaba Szegedi
Ranch Hand

Joined: Mar 27, 2010
Posts: 36
Hello,

I have a loop with db modifications and every loop ended with commit.

What if a commit throws exception ? As I know we must try to rollback.
But do we need to continue the loop ?

As for me I would exit from the function with a return false (after the connection.close) or what ever, forcing the further db modifications is pointles then.
Is this would be the best way or exists another ?

Thanks for your suggestion in advance.


Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26200
    
  66

It's going to depend on your requirements. If you want to rollback the whole thing on failure, you wouldn't commit each time through the loop - only at the end.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: what if jdbc commit throws exception in a loop ?
 
Similar Threads
Regarding transaction updates
Help with Determining Cause of Error Messages
Should Bean developer throw RemoteException & related stuff
CMT doesn't commit DB changes in a POJO
Apache Derby or MySQL