3 Replies Latest reply on Oct 30, 2002 11:58 AM by Julian Gosnell

    Transaction Problem

    Vicky Kak Master

      Hi,
      Following is section of my code but this gets hang when called and gives the Timed out Transaction after some time,Can you guys share your experience to solve the problem
      *******************************************
      Context ocontext=new InitialContext();
      DataSource ods=(DataSource)ocontext.lookup("java:/XAOracleDS");
      //DataSource ods=(DataSource)ocontext.lookup("java:/DefaultDS");
      out.println("Data Source is "+ods);
      Connection ocon=ods.getConnection();
      Statement ostmt=ocon.createStatement();
      //ResultSet ors=ostmt.executeQuery("select * from tab");
      int i=10;
      UserTransaction trans=(UserTransaction)ocontext.lookup("UserTransaction");
      out.println("Value Of i before begin:"+i+"");
      trans.begin();
      //trans.setRollbackOnly();
      ostmt.executeUpdate("update gangsterejb set id=1 where id=3");
      i++;
      //trans.commit();
      out.println("Value Of i:"+i+"");
      out.println(trans+"");
      *******************************************
      Here every thing is configured properly I mean XADataSource.
      regards
      Vicky

        • 1. Re: Transaction Problem
          Vicky Kak Master

          Also when I call trans.commit(),it gives the problem of hanging.If I dont give commit it gets executed but there is not update in DataBase.
          regards
          Vicky

          • 2. Re: Transaction Problem
            Vicky Kak Master

            Hi,
            I am waiting for your feedback.I would appreciate if someone from the development team of Jboss helps in this issue.
            I have been trying the same code with minor modifications as shown
            **********************************************************
            <%@ page import="javax.naming.*,javax.sql.*,java.sql.*,project.session.login.*,javax.transaction.*" %>
            <%
            Context ocontext=new InitialContext();
            DataSource ods=(DataSource)ocontext.lookup("java:/XAOracleDS");
            //DataSource ods=(DataSource)ocontext.lookup("java:/OracleDSI");
            System.out.println("Data Source is "+ods);
            Connection ocon=ods.getConnection();
            ocon.setAutoCommit(true);
            PreparedStatement ostmt=ocon.prepareStatement("update gangsterejb set name=? where id = ? ");
            ostmt.setString(1,"VK1");
            ostmt.setString(2,"3");
            //ostmt.executeUpdate();
            System.out.println("Before getting UserTransaction");
            UserTransaction trans=(UserTransaction)ocontext.lookup("UserTransaction");
            //ResultSet ors=ostmt.executeQuery("select * from tab");
            int i=10;
            trans.setTransactionTimeout(10);
            System.out.println("After Timeout");
            out.println("Value Of i before begin:"+i+"");
            trans.begin();
            System.out.println("After Begin");
            //trans.setRollbackOnly();
            System.out.println("STATUS_ACTIVE "+Status.STATUS_ACTIVE);
            System.out.println("Get Status "+trans.getStatus());
            //ostmt.executeUpdate("update gangsterejb set name='1' where id = 3 ");
            System.out.println("After update");
            i++;
            //trans.commit();
            System.out.println("Before Commit "+ocon.getAutoCommit());
            //trans.rollback();
            ostmt.executeUpdate();
            //trans.commit();
            System.out.println("After Commit");
            ocon.close();
            out.println("Value Of i:"+i+"");
            out.println(trans+"");

            %>

            **********************************************************

            And the o/P I get
            ************************
            17:37:18,464 INFO [STDOUT] Data Source is org.jboss.resource.adapter.jdbc.local
            .LocalDataSource@47098a
            17:37:18,995 INFO [STDOUT] Before getting UserTransaction
            17:37:18,995 INFO [STDOUT] After Timeout
            17:37:19,005 INFO [STDOUT] After Begin
            17:37:19,005 INFO [STDOUT] STATUS_ACTIVE 0
            17:37:19,005 INFO [STDOUT] Get Status 0
            17:37:19,005 INFO [STDOUT] After update
            17:37:19,005 INFO [STDOUT] Before Commit true
            17:37:29,111 WARN [TxCapsule] Transaction XidImpl [FormatId=257, GlobalId=VIDYA
            DHAR-D//2, BranchQual=] timed out. status=STATUS_ACTIVE
            ************************
            It gets held once the execute() is called.
            regards
            Vicky

            • 3. Re: Transaction Problem
              Julian Gosnell Expert

              I can't see anything relevant to :

              HTTPD, Servlets & JSP

              here.

              If you posted a/the relevant forum, you would be more likely to come across someone with the relevant expertise.

              Jules