You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ravindar Roopreddy <rr...@callidussoftware.com> on 2002/09/06 18:45:53 UTC

Help with UserTransaction using Tyrex 9.7.0/Oracle 8.1.7/Tomcat4.0.4

I am trying to get the "UserTransaction" working with Following setup :

- Tomcat 4.0.4, Oracle 8.1.7 JDBC driver (classes12.zip) and Tyrex 9.7.0

I get the following exception. I tried different combinations without much luck. I saw some posts that seems to think the
exception is because the JDBC driver is non-xa. When I try Oracle XA driver (commented out below in server.xml) I get
null data source at JNDI lookup time.

I would really appreciate if anybody has a working setup with the above configuration and willing share. I could not find
any documentation as to how to get this working.

Thanks
-Ravi R
---------------------------------------------

javax.transaction.HeuristicRollbackException: Transaction has been rolled back
	at tyrex.tm.TransactionImpl.commit(TransactionImpl.java:724)
	at tyrex.tm.TransactionImpl.commit(TransactionImpl.java:648)
	at tyrex.tm.TransactionManagerImpl.commit(TransactionManagerImpl.java:222)
	at tyrex.tm.UserTransactionImpl.commit(UserTransactionImpl.java:105)
	at org.apache.jsp.dbtest$jsp._jspService(dbtest$jsp.java:123)

Here is my sample configuration and JSP code :

1. server .xml (If I enable the "oracle XA driver, comment out here,  I get null DataSource in JSP)

          <Resource name="myDS" auth="Container" type="tyrex.jdbc.ServerDataSource"/>
		<ResourceParams name="myDS">
			<parameter><name>user</name><value>RAVI</value></parameter>
			<parameter><name>password</name><value>TEST</value></parameter>
			<parameter><name>driverClassName</name><value>oracle.jdbc.driver.OracleDriver</value></parameter>
			<!-- parameter><name>driverClassName</name><value>oracle.jdbc.xa.client.OracleXADataSource</value></parameter -->
			<parameter>
				<name>driverName</name>
				<value>jdbc:oracle:thin:@helios:1521:vcd1</value>
			</parameter>
			<parameter>
				<name>maxActive</name>
				<value>32</value>
			</parameter>
			<parameter>
				<name>maxIdle</name>
				<value>4</value>
			</parameter>
		</ResourceParams>

2. web.xml

<resource-ref>
	<res-ref-name>myDS</res-ref-name>
	<res-type>javax.sql.DataSource</res-type>
	<res-auth>Container</res-auth>
</resource-ref>

3. Test jsp

<%@ page import=" java.util.Collection,
		java.util.Iterator,,
                         javax.naming.*,
                         javax.sql.*,
                         java.sql.*,
                         javax.transaction.*,
                         javax.naming.*"%>
<html>
  <head>
    <title>DB Test</title>
  </head>
  <body>

  <%
      InitialContext initCtx = new InitialContext();
      Context envCtx = (Context) initCtx.lookup("java:comp/env");
      //DataSource ds = null;
      Connection conn = null;

      Object tx = (new InitialContext()).lookup("java:comp/UserTransaction");
      UserTransaction utx = (UserTransaction) tx;

      System.out.println("Get status:"+utx.getStatus());

      // If I try the following line I get ClassCastException, the next line seems to work ok
      //ds = (DataSource)envCtx.lookup("myDS");
      tyrex.jdbc.xa.EnabledDataSource ds = (tyrex.jdbc.xa.EnabledDataSource)envCtx.lookup("myDS");
      System.out.println("Data source:"+ds);
      conn = ds.getConnection();
      conn.setAutoCommit(false);
              
      utx.begin();

        if(conn != null)  {
            Statement stmt = conn.createStatement();
            stmt.executeUpdate("UPDATE USER SET USERNAME='yyyyy' WHERE PASSWORD='pwd'");
        }

      utx.commit();
  %>
  </body>
</html>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>