This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JDBC and the fly likes Illegal operation exception while trying rollback.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Illegal operation exception while trying rollback.." Watch "Illegal operation exception while trying rollback.." New topic
Author

Illegal operation exception while trying rollback..

Rambo Rambabu
Greenhorn

Joined: Jul 12, 2002
Posts: 21
Hi,

I am developing some session beans with WSAD4.0 , JDBC for OracleThin(classes12.zip), Oracle 8.05. In one of the session bean, I am trying to use callablestatement for updating a table. I am getting an error. When I try the same statmenet directly in SQL, I get an exception saying ORA-01031: insufficient privileges. I need to know how to xlate this actual Oracle exception to the end user to give a proper message.
I am getting this Illegal operation exception from WSAD..
java.lang.IllegalStateException: Illegal operation: tried to commit connection in global tran
exception while I am doing a rollback.
here is my sample code:
updateemployee(string param_passcode){
Connection con = null;
CallableStatement updateEmployee = null;
String sql="";
int noOfRowsUpdated = 0;
Vector works = new Vector();
Employee employee = new Employee();
try
{
con = com.ameritech.pa.common.Util.getConnection();

sql = "BEGIN "+
"UPDATE employee "+
"SET effective_start_date = to_date(?,'MM/DD/YYYY') ,"+
"update_user_id = ?, "+
"update_datetime = SYSDATE "+
"WHERE passcode = ? "+
"AND effective_start_date = TO_DATE(?,'MM/DD/YYYY') ;"+
"END; " ;

System.out.println("The sql is " + sql);

updateEmployee = con.prepareCall(sql);

updateEmployee.setString(1, param_newEffectiveStartDate);
updateEmployee.setString(2, param_loggedInPasscode);
updateEmployee.setString(3, param_passcode);
updateEmployee.setString(4, param_oldEffectiveStartDate);

noOfRowsUpdated = updateEmployee.executeUpdate();

System.out.println("no of rows updated :" + noOfRowsUpdated);
if (noOfRowsUpdated == 0)
{
con.rollback();
return 1;
}
else
{
con.commit();
return 0;
}
}
catch (SQLException s)
{
s.printStackTrace();
}

catch (Exception e)
{
e.printStackTrace();
}

finally
{
try
{
if (updateEmployee != null) updateEmployee.close();
if (con != null) con.close();
}
catch (SQLException se){}
}
return 0;
}
thank You.
John Carnell
Author
Ranch Hand

Joined: Sep 27, 2002
Posts: 71
Originally posted by Rambo Rambabu:
Hi,

I am developing some session beans with WSAD4.0 , JDBC for OracleThin(classes12.zip), Oracle 8.05. In one of the session bean, I am trying to use callablestatement for updating a table. I am getting an error. When I try the same statmenet directly in SQL, I get an exception saying ORA-01031: insufficient privileges. I need to know how to xlate this actual Oracle exception to the end user to give a proper message.
I am getting this Illegal operation exception from WSAD..
java.lang.IllegalStateException: Illegal operation: tried to commit connection in global tran

Hi,
Are you using container manager or bean managed transactions for your session EJB. If you are using container managed transactions (by declaring them in the EJB deployment descriptor) you will get the above exception because the container is responsible for managing the transaction. You should not be trying to commit or rollback() on the connection in CMT-based session beans. Instead, you should let the container manage the transaction. If you want to signal a rollback in a CMT transaction then issue a setRollBack call on the EJB's context object.
I hope that helps.
Thanks,
John


John Carnell<br />Principal Architect<br /> <br />Netchange, LLC<br />1161 HillCrest Heights<br />Green Bay, WI 54313<br /> <br />john.carnell@netchange.us<br /> <br /> <br />Author of <a href="http://www.amazon.com/exec/obidos/ASIN/159059228X/ref=jranch-20" target="_blank" rel="nofollow">Pro Jakarta Struts, Second Edition</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Illegal operation exception while trying rollback..