Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what if jdbc commit throws exception in a loop ?

 
Csaba Szegedi
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34671
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic