File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and the fly likes How to handle connection failure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to handle connection failure" Watch "How to handle connection failure" New topic

How to handle connection failure

V Patil
Ranch Hand

Joined: Oct 04, 2008
Posts: 36
I am using several insert statements in a method in Java.
If the connection fails in between I want to roll back the inserted rows.
I cant use con.rollback(), because there is no connection.
How to handle such situation?
Thanks in advance.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 39543
If no explicit commit has been given at the time the connection goes away, then the transaction is automatically rolled back by the server. The client doesn't need to do anything about it (apart form handling the client-side aspects).

Ping & DNS - updated with new look and Ping home screen widget
V Patil
Ranch Hand

Joined: Oct 04, 2008
Posts: 36
Thanks a lottt for resolving my query.
Srikanth Nalam

Joined: Feb 23, 2010
Posts: 20
just add to this, transaction auto commit should be false.

Thanks & Regards,
Srikanth Nalam.
I agree. Here's the link:
subject: How to handle connection failure
Similar Threads
How to handle a JDBC DAO 's Exception?
Connection Question
applet to IIS via sockets
Invoking REST webservices.