aspose file tools*
The moose likes JDBC and the fly likes How to handle sql exception for Connection.rollback Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to handle sql exception for Connection.rollback" Watch "How to handle sql exception for Connection.rollback" New topic
Author

How to handle sql exception for Connection.rollback

anuj sahai
Greenhorn

Joined: Dec 02, 2000
Posts: 8
Hi,
I have a set of transactions to be performed and incase any of them goofs up I need to rollback. I therefore catch and rollback in the catch for SQLException. However conn.rollback() itself throws a SQLException. I am currently handling it by a try within a catch. The code sample is below :
catch (SQLException e) {
try{
conn.rollback();
Logger.logProblem();
}
catch (SQLException sqle) {
String name = "Errror in trying to rollback:" + new java.util.Date();
Logger.logProblem(name);
}
catch (SQLException sqle) {
String name = " SQl Errror:" + new java.util.Date();
Logger.logProblem(name);
}
}
Please let me know if there ia a better way in which this is handeled in applications...
thanxs
schandu999
Greenhorn

Joined: Feb 07, 2002
Posts: 9
hi
There may be problem in your conn , see whether this object is getting created or not , Coz if
conn.rollback();
is throwing the exception then check it with null
pls see the code below
thanks

catch (SQLException e) {
try{
//*****************
if(conn != null)
//****************
conn.rollback();
Logger.logProblem();
}
catch (SQLException sqle) {
String name = "Errror in trying to rollback:" + new java.util.Date();
Logger.logProblem(name);
}
catch (SQLException sqle) {
String name = " SQl Errror:" + new java.util.Date();
Logger.logProblem(name);
}
}
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

what is the SQLError message that is being thrown at conn.rollback?

What's the error message?
Jamie
[ February 07, 2002: Message edited by: Jamie Robertson ]
 
Consider Paul's rocket mass heater.
 
subject: How to handle sql exception for Connection.rollback