• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to handle sql exception for Connection.rollback

 
anuj sahai
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic