File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes JAVA with AS/400 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JAVA with AS/400" Watch "JAVA with AS/400" New topic
Author

JAVA with AS/400

radhika sharma
Greenhorn

Joined: Oct 06, 2005
Posts: 5
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

Joined: Dec 20, 2006
Posts: 2495
    
    8

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


OCUP UML fundamental and ITIL foundation
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JAVA with AS/400