Did you try it and it didn't work.

In a J2EE environment closing a connection you got from the server does
not close the actual underlying connection until the transaction either
commits or rollsback. The following is doable:

utx.begin();
conn = ( (DataSource) ctx.lookup( "jdbc:/comp/env/jdbc/mydb" )
).getConnection();
... do something
conn.close();
utx.rollback();

Note that I'm using the DataSource API which is the recommended way for
dealing with connections, but the WebLogic JDBC driver should work just
as well.

arkin


Sethuraman Ramanathan wrote:
>
> hello all,
>
>   I have a question how to combine ejb transaction with database transaction
> in BMP
>
> try
>   {
>     UserTransaction utx = lookup(...)
>     utx.begin();
>        (line 1 )       EmployeeHome empHome = lookup(..);
>        (line 2 )       Employee emp = empHome.find("abc");
>        (line 3 )       emp.remove();
>        (line 4 )       emp = empHome.find("xyz");
>        (line 5 )       emp.remove();
>      utx.commit();
>   }
>   catch ( Exception ex )
>   {
>      ex.rollback();
>   }
>
> Employee Bean .....
>
> public void ejbremove()
> {
>
>       Connection con = DriveManager.getConnection
>                                ("jdbc:weblogic:jts:dbPool","null);
>       CallableStatement cs = null;
>
>     try
>     {
>       cs = con.preparecall(sql);
>       cs.execute();
>     }
>     catch ( SQLException sqlex )
>     {
>       cs.close();
>     }
>     finally
>     {
>       con.close();  // by closing  are you commiting ???
>    /*
>     ??? do you close here or not
>     ??? if you are closing what hapens to the user transaction failure
>     ??? if you are not closing then what hapens if this function is called
> in a loop
>    */
>      }
> }
>
> My transaction should remove both employees, i am making connection to
> database in ejbRemove function of employee and call some proc then close the
> connection
>
> Question 1)
>         since i close the connection transaction succeed or not the
> connection is committed , how do you rollback if it is failed
>
> question 2)
>         if i am not closing the connection and if transaction fails then it
> transaction will automatically rollback the connection it has also, question
> is then how will i close the connection
>
> -Thanks
> sethu
>
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
>
> ===========================================================================
> 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".

--
----------------------------------------------------------------------
Assaf Arkin                                           www.exoffice.com
CTO, Exoffice Technologies, Inc.                        www.exolab.org

===========================================================================
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