This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases 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 and Relational Databases
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: 32481
    
214

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.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: what if jdbc commit throws exception in a loop ?
 
jQuery in Action, 3rd edition