Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAVA with AS/400

 
radhika sharma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using java as my front end, and have AS/400 files at the back end. I am using JDBC diver to connect to AS/400 in my Session EJB. Now my problem is I have transactions, in which either all the queries should sucess, or all should fail. LIke if first query succeeds, and second query fails, then I need to roll back the earlier transaction also.

I tried the following code:

boolean trRoll = false;
try{
Connection conn = getAS400Connection();
conn.setAutoCommit(false);
String qry = "INSERT INTO HSWESTWOOD.WSTWDNISEQ (USERID, SESSIONID, DTSTAMP) VALUES('56','SESSION1234566','200705010944')";
PreparedStatement pstmt = conn.prepareStatement(qry);
pstmt.executeUpdate();
String qrey = "INSERT INTO HSWESTWOOD.WSTWDNISEQ (USERID, SESSIONID, DTSTAMP) VALUES('2wrerwrwrwerwrwrwrwrwrwrwerwrwrwe','SESSION1234566','200705010944')";
PreparedStatement pstmt1 = conn.prepareStatement(qrey);
pstmt1.executeUpdate();

}catch(Exception e){
try{
conn.rollback();
trRoll=true;
}
catch(Exception se){
System.out.println("SQLExceptionSQLExceptionSQLExceptionSQLExceptionSQLExceptionSQLExceptionSQLExceptionSQLExceptionSQLException" +se);
}
e.printStackTrace();
}
closeAS400Connection(conn);
return trRoll;
}

But its throwing an exception following Exception:You cannot rollback during a managed transaction!


13:43:42,060 INFO [STDOUT] before westwoodEJB.testTransaction();
13:43:42,060 INFO [STDOUT] SQLExceptionSQLExceptionSQLExceptionSQLExceptionSQLExceptionSQLExceptionSQLExceptionSQLExcep
tionSQLExceptionjava.sql.SQLException: You cannot rollback during a managed transaction!
13:43:42,060 ERROR [STDERR] java.sql.SQLException: You cannot set autocommit during a managed transaction!
13:43:42,060 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.setJdbcAutoCommit(BaseWr
apperManagedConnection.java:482)
13:43:42,060 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.WrappedConnection.setAutoCommit(WrappedConnection.jav
a:322)


Can you please help me out guys.
Thanks Alot in Advance

radhika
 
Jan Cumps
Bartender
Posts: 2602
13
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not an error from your database, but from JBoss's BaseWrapperManagedConnection class.

Is it possible to define your datasource as type <local-tx-datasource> instead of <xa-tx-datasource>?

Regards, Jan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic