Transaction Problem!!!
vickyk Oct 30, 2002 8:18 AMHi,
This has alreasy been posted in other section but did not get any response there so I am putting it here now.
I hava a Jsp where I wanted the JTA,to handle the Transaction.I have created the XADataSource and I am Calling the executeUpdate after starting the Transaction as shown below:
<%@ 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+"");
%>
The Output which I get from this follows
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
The "After Commit" statement does not get displayed on the console.I have tried various options and found if I comment ostmt.executeUpdate(); the code goes to completion.I am not able to solve the problem /I would appericiate if you could try this.
regards
Vicky