>     Where do we set the autocommit option for the DataSource?

You don't need to - the app server will do this for you when a transaction
is started either by the container (in case of CMT) or by the bean (in case
of BMT)

-Saurabh

> Is it container specific? The ejb spec doesn't mention anything regarding
the DataSource. Do
> i explicitly have to set the autocommit in the Session bean code if i want
to
> roll back the transaction in the event of an system exception
> orsessionContext.setRollBackOnly().

> Cheers
> Sachin
>
> PS: using JBoss 2.4.4.
>
> So how does the
> On Thursday 20 June 2002 09:22, Karthikeyan M wrote:
> > Hi,
> >
> > Did you make sure you have configured weblogic to use TxDataSource
instead
> > of normal DataSource for the obtaining db connections. If you are using
> > just DataSource for obtaining connections, weblogic runs in auto-commit
> > mode.
> >
> > -karthik.
> >
> > Ashwani Kalra wrote:
> > > hi,
> > > I checked at my db. The autocommit feature is off.  It works only when
In
> > > my session bean I  write connection.setAutocommit(false).
> > > Why is this happening ??
> > >
> > > Ashwani
> > >
> > > ----- Original Message -----
> > > From: "Ashwani Kalra" <[EMAIL PROTECTED]>
> > > To: <[EMAIL PROTECTED]>
> > > Sent: Wednesday, June 19, 2002 5:36 PM
> > > Subject: Re: Transaction in SFSB
> > >
> > > > Hi,
> > > > I tried your scenario. I used connection.setAutocommit(false) in my
> > > > code
> > >
> > > and
> > >
> > > > it works fine. It means at the db end autocommit feature should be
off.
> > >
> > > If
> > >
> > > > I dont use connection.setAutocommit(false) then in catch block even
if
> > > > I
> > >
> > > do
> > >
> > > > Context.setRollbackOnly() , it doesnt work.
> > > >
> > > > Ashwani
> > > >
> > > > ----- Original Message -----
> > > > From: "Hemant Arora" <[EMAIL PROTECTED]>
> > > > To: <[EMAIL PROTECTED]>
> > > > Sent: Wednesday, June 19, 2002 1:46 PM
> > > > Subject: Transaction in SFSB
> > > >
> > > > > Hi Ashwin
> > > > >
> > > > > Sorry for yesterday's mail.
> > > > >
> > > > > Actually I forgot to write some details of the transactions in my
> > > > > code
> > > > >
> > > > > Please find the latest code
> > > > >
> > > > > I do not have the "Account" table in my database
> > > > >
> > > > > so when I try to inseret the 2 queries
> > > > >
> > > > > then the second one should fail as its happening and the first
insert
> > > > > should rollback as there is
> > > > >
> > > > > Sql exception in the second query
> > > > >
> > > > > The weblogic console shows this error which is correct as per my
> > > > > understanding
> > > > >
> > > > > Wed Jun 19 12:42:35 GMT+05:30 2002:<I> <EJB JAR deployment
> > > > > d:/weblogic/myserver/romanCount.jar> Transaction:
'1024470662649_3'
> > >
> > > rolled
> > >
> > > > > back due to EJB excep
> > > > > tion:
> > > > > java.rmi.RemoteException: ORA-00942: table or view does not exist
> > > > >         at
> > >
> > >
com.wiley.compBooks.roman.session.Count.CountBean.dbconnection(CountBean.
> > >jav
> > >
> > > > a:88)
> > > >
> > > > >         at
> > >
> > >
com.wiley.compBooks.roman.session.Count.CountBeanEOImpl.dbconnection(Coun
> > >tBe
> > >
> > > > anEOImpl.java:148)
> > > >
> > > > >         at
> > >
> > >
com.wiley.compBooks.roman.session.Count.CountBeanEOImpl_WLSkel.invoke(Cou
> > >ntB
> > >
> > > > eanEOImpl_WLSkel.java:83)
> > > >
> > > > >         at
> > >
> > >
weblogic.rmi.extensions.BasicServerObjectAdapter.invoke(BasicServerObject
> > >Ada
> > >
> > > > pter.java:338)
> > > >
> > > > >         at
> > >
> > >
weblogic.rmi.extensions.BasicRequestHandler.handleRequest(BasicRequestHan
> > >dle
> > >
> > > > r.java:69)
> > > >
> > > > >         at
> > >
> > >
weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.jav
> > >a:1
> > >
> > > > 5)
> > > >
> > > > >         at
weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
> > > > >
> > > > >
> > > > > but when i see the database table "Accounts" The record does
exists ,
> > > > > it should have been rolled back
> > > > >
> > > > > Any help
> > > > >
> > > > > Regards
> > > > > Hemant
> > > > >
> > > > >
> > > > > package com.wiley.compBooks.roman.session.Count;
> > > > >
> > > > > import javax.ejb.*;
> > > > > import java.sql.Connection;
> > > > > import java.sql.PreparedStatement;
> > > > > import java.sql.ResultSet;
> > > > > import java.sql.SQLException;
> > > > > import java.sql.*;
> > > > > import javax.naming.NamingException;
> > > > > import javax.naming.InitialContext;
> > > > > import javax.transaction.UserTransaction;
> > > > > 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;
> > > > >           System.out.println("INSIDE dbconnection");
> > > > >           String strGotit = "";
> > > > >                Connection con = null;
> > > > >                PreparedStatement stmt = null;
> > > > >                PreparedStatement stmt1 = null;
> > > > >
> > > > >           try
> > > > >           {
> > > > >
> > > > >                initCtx = new InitialContext();
> > > > >                ds = (javax.sql.DataSource)
> > > > >                initCtx.lookup("oraclePool");
> > > > >              con = ds.getConnection();
> > > > >
> > > > >                 stmt = con.prepareStatement("insert into accounts
> > > > > (id,name,balance) values(?,?,?) ");
> > > > >
> > > > >              stmt.setInt(1,1);
> > > > >              stmt.setString(2,"Tester 1");
> > > > >              stmt.setInt(3,1212);
> > > > >
> > > > >              if(stmt.executeUpdate() != 1){
> > > > >                          throw new RemoteException("Insert
Failed");
> > > > >                 }
> > > > >
> > > > >              stmt1 = con.prepareStatement("insert into account
> > > > > (id,name,balance) values(?,?,?) ");
> > > > >
> > > > >              stmt1.setInt(1,2);
> > > > >              stmt1.setString(2,"Tester 2");
> > > > >              stmt1.setInt(3,1212);
> > > > >
> > > > >              if(stmt1.executeUpdate() != 1){
> > > > >                          throw new RemoteException("Insert
Failed");
> > > > >                 }
> > > > >
> > > > >
> > > > >           }catch(javax.naming.NamingException ne){
> > > > >                     throw new EJBException(ne);
> > > > >           }catch(SQLException sqe)
> > > > >           {
> > > > >                throw new RemoteException(sqe.getMessage());
> > > > >           }
> > > > >           finally
> > > > >           {
> > > > >                try
> > > > >                {
> > > > >                                    stmt.close();
> > > > >                                    stmt1.close();
> > > > >                                    con.close();
> > > > >
> > > > >                     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".
> > >
> > >
=========================================================================
> > >== 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".
>
> --
> Sachin Pandey
> Nuix Pty Ltd
> (61)(02) 92839010
>
> U can't erase my dreams, u can only wake me up.
>
>
===========================================================================
> 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".

Reply via email to