0 Replies Latest reply on Jun 22, 2006 10:11 AM by yan zhensong

    How to use JTA in servlet? Please help me,thank you!

    yan zhensong Newbie

      I am using Jboss 4.0.4 GA,JDK1.5.0_01. My database is informix.
      When I use JTA in Tomcat,it always failed,please help me,Thanks!
      My code is:
      String ls_sql=null;
      Context ctx=null;
      UserTransaction ut=null;
      Connection conn=null;
      Connection conn1=null;
      try{
      ctx = new InitialContext();
      ut=(UserTransaction)ctx.lookup("java:/comp/UserTransaction");
      ut.begin();

      DataSource ds = (DataSource) ctx.lookup"java:/comp/env/jdbc/szjdcdb");
      ls_sql=" update y_user set username='yzs' where usercode='001'";
      conn=ds.getConnection();
      Statement stmt=conn.createStatement();
      stmt.execute(ls_sql);
      stmt.close();


      DataSource ds1 = (DataSource) ctx.lookup("java:/comp/env/jdbc/szxmgl");
      ls_sql=" update y_user set username='yzs' where usercode='001'";
      conn1=ds.getConnection();
      Statement stmt1=conn.createStatement();
      stmt1.execute(ls_sql);
      stmt1.close();

      request.setAttribute("sql","ok");


      ut.commit();


      }catch(Exception e){
      ut.rollback();
      request.setAttribute("error",e.toString());
      request.setAttribute("sql",ls_sql);
      return mapping.findForward("failed");
      }finally{

      conn.close();
      conn1.close();
      }

      Jboss didn't report errors,but table is locked,Why ?