Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

UserTransaction doesn't commit or rollback (JOTM)

843859Jul 31 2005 — edited Feb 6 2006
Hello

I am using tomcat 4.1 with Postgres 7.2. I'm working on adding transaction support through UserTransaction with JOTM.

The following code does never commit:

#calling code
    Context ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/mydb");
    ut = (UserTransaction)ctx.lookup("java:comp/UserTransaction");
    c = ds.getConnection();
    c.setAutoCommit(false);
    ut.begin();
        PreparedStatement s = c.prepareStatement(...);
        s.executeUpdate();
    ut.commit();
#server.xml
<Context ....>
          <Resource name="jdbc/mydb" auth="Container"
                    type="javax.sql.DataSource"/>
          <ResourceParams name="jdbc/mydb">
            <parameter><name>username</name><value>postgres</value></parameter>
            <parameter><name>password</name><value>postgres</value></parameter>
            <parameter>
              <name>driverClassName</name>
              <value>org.postgresql.Driver</value>
            </parameter>
            <parameter>
              <name>url</name>
              <value>jdbc:postgresql://localhost/mydb?charSet=LATIN1</value>
             </parameter>
         </ResourceParams>

		 <Resource name="UserTransaction" auth="Container"
				type="javax.transaction.UserTransaction"/>
     	 <ResourceParams name="UserTransaction">
			<parameter>
			  <name>factory</name>
			  <value>org.objectweb.jotm.UserTransactionFactory</value>
			</parameter>
			<parameter>
			  <name>jotm.timeout</name>
			  <value>120</value>
			</parameter>
		  </ResourceParams>
 </Context>
JOTM is perfectly loaded after the JNDI lookup for the UserTransaction (as seen in the console output), but Transactions do not work at all.

If I leave out the setAutoCommit statement, then the connection will stay in autocommit mode and the update works of course.

Any ideas?

Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 6 2006
Added on Jul 31 2005
8 comments
696 views