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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30965
    
158

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://aspose.com/file-tools
 
subject: what if jdbc commit throws exception in a loop ?