You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Peter Neu <pe...@gmx.net> on 2004/12/19 14:18:38 UTC

Handling Transcation Errors

Hello everybody,

I was wondering what is the best way to cope with transaction errors in a
Struts application. I use JDBC to connect to the database. When I try to do
an insert-transaction it looks like the code below the message (sample 
form the Sun Tutorial).

My question is: what should I do when an update query fails
and the client has to submit the query again?

I'm using a Servlet Container (Tomcat 5.0.27) and no EJB's.

Best Regards,

Peter


public void ship (String productId, String orderId, int 
quantity) {

   try {
      con.setAutoCommit(false);
      updateOrderItem(productId, orderId);
      updateInventory(productId, quantity);
      con.commit();
   } catch (Exception ex) {
       try {
          con.rollback();
          throw new  Exception("Transaction failed: " +
             ex.getMessage());
       } catch (SQLException sqx) {
           throw new  Exception("Rollback failed: " +
              sqx.getMessage());
       }
   }
} 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org