File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Commit & Rollback using java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Commit & Rollback using java?" Watch "Commit & Rollback using java?" New topic

Commit & Rollback using java?

Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276

I have a stored procedure in which i have four insert statements .Now i want to commit each insert statement if it gets successfully executed .By chance if any exception occurs while doing any particular insert i want to rollback each of the inserts so that atomicity exists in the tables.

So how to do this through my java code & where these methods or constants for commit & rollback shoul be written when using the CallableStatement???

[ April 04, 2006: Message edited by: Bear Bibeault ]


The Art Of Life Is To Know When To Be Useless And When To Be Useful - CHUANG TZU
Mattias Arthursson
Ranch Hand

Joined: Jul 26, 2004
Posts: 90
You'll want to call setAutoCommit(false) on the Connection before doing anything else. Once you're done with your statements, call commit() or rollback() (on the Connection) respectively.

Admit nothing. Blame everyone. Be bitter.
I agree. Here's the link:
subject: Commit & Rollback using java?
It's not a secret anymore!