Why it would revert back the insert query??
It will happen when any system exception is thrown or you set the status of
the transaction to setRollback.
Ashwani
----- Original Message -----
From: "Hemant Arora" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, June 18, 2002 7:53 PM
Subject: Transaction in Statefull session bean
> Hi
>
> I'm facing a problem in SFSB
>
> Here is the code of the bean
>
> The transaction attribute in the descriptior is Container managed
> so it should revert back the insert query
> but the row is added in the DB as per the insert query
>
> Please help
>
> Regards
> Hemant
>
>
> package com.wiley.compBooks.roman.session.Count;
>
> import javax.ejb.*;
> import java.sql.Connection;
> import java.sql.Statement;
> import java.sql.ResultSet;
> import java.sql.SQLException;
> import java.sql.*;
> import javax.naming.NamingException;
> import javax.naming.InitialContext;
> import javax.sql.DataSource;
> import java.rmi.RemoteException;
> import java.io.*;
>
> /**
> * Demonstration Stateful Session Bean. This Bean is initialized
> * to some integer value, and has a business method which
> * increments the value.
> *
> * This example shows the basics of how to write a stateful
> * session bean, and how passivation/activation works.
> */
> public class CountBean implements SessionBean{
>
> SessionContext ctx;
> // The current counter is our conversational state.
> public int val;
>
> //
> // Business methods
> //
>
> /**
> * Counts up
> */
> public int count() {
> System.out.println("count()");
> return ++val;
> }
>
> /**
> * Counts up
> */
> public String dbconnection() throws RemoteException,SQLException
> {
> InitialContext initCtx = null;
> DataSource ds = null;
> String strGotit = "";
> Connection con = null;
> Statement stmt = null;
> Statement stmt1 = null;
>
> try
> {
>
> initCtx = new InitialContext();
> ds = (javax.sql.DataSource)
> initCtx.lookup("oraclePool");
> while((con = (ds.getConnection())) == null){}
>
> stmt = con.createStatement();
>
> stmt1 = con.createStatement();
>
> stmt1.execute("insert into accounts
> values(2,'XXXX',1212121)");
> stmt.executeUpdate("update accounts set name = 'Tester',
> balance = 12121 where id = (select id from account where name ='hi')");
>
>
> stmt.close();
> stmt1.close();
> con.close();
>
>
> }
> catch(Exception ne)
> {
> System.out.println("HERE" + ne);
> }
> finally
> {
> try
> {
> if(initCtx != null)
> initCtx.close();
> file://return ds.getConnection();
> }
> catch(NamingException ne)
> {
> file://log("Error closing context: " + ne);
> throw new EJBException(ne);
> }
> }
>
> return strGotit;
> }
>
> //
> // EJB-required methods
> //
>
> public void ejbCreate(int val) throws CreateException {
> this.val = val;
> System.out.println("ejbCreate()");
> }
>
> public void ejbRemove() {
> System.out.println("ejbRemove()");
> }
>
> public void ejbActivate() {
> System.out.println("ejbActivate()");
> }
>
> public void ejbPassivate() {
> System.out.println("ejbPassivate()");
> }
>
> public void setSessionContext(SessionContext ctx) {
> }
> }
>
> -----------------------Disclaimer------------------------
>
> The views of the author may not necessarily reflect those
> of the Company. All liability is excluded to the extent
> permitted by law for any claims arising as a result of the
> use of this medium to transmit information by or to
> IT Solutions (India) Pvt. Ltd.
>
> We have taken precautions to minimize the risk of
> transmitting software viruses, but we advise you to
> carry out your own virus checks on any attachment to
> this message. We cannot accept liability for any loss or
> damage caused by software viruses.
>
> ------------------------Disclaimer------------------------
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff EJB-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".