This content has been marked as final.
Show 2 replies
-
1. Re: How tom make a jdbc request inside Stateless EJB method
adrian.brock Mar 20, 2003 8:16 PM (in response to noel.rocher)Look up the datasource and ask for a connection.
The jca wrapper will enroll the connection in the
current transaction.
Make sure you close the connection and any statements
in a finally block to return them to the pool.
Regards,
Adrian -
2. Re: How tom make a jdbc request inside Stateless EJB method
guix Dec 7, 2007 6:52 AM (in response to noel.rocher)"adrian@jboss.org" wrote:
Look up the datasource and ask for a connection.
The jca wrapper will enroll the connection in the
current transaction.
Make sure you close the connection and any statements
in a finally block to return them to the pool.
Regards,
Adrian
Hi:
I am trying this in Jboss 4.0.4 and it does not work:
example:protected EJBContext myContext = null; public void setSessionContext (SessionContext ctx){ myContext = ctx; } public void setUserData(String userId, String name, String roleId) throws RemoteException{ try { UserLocal userLocal = UserFactoryLocal.getUser (userId); //Userlocal is an entity bean userLocal.setRoleId(roleId); Object object = myContext.lookup("java:/" + myDataSourceName); // Same datasoiurce name as the bean uses, it is a local datasource name Connection connection = ((DataSource)object).getConnection(); connection.execute("update usuario set rol = '" + roleId + "' where usuario = '" + userId + "'"; connection.close(); userLocal.setUserName(name); //if this set fails there is no rollback performed to the previous execute } catch (Exception e) { e.printStackTrace(); throw new EJBException(e); } }
The example as you can see is functionalitywise, bogus, but I can see that if the code fails in setUserName then the new role appears set in the database eventhoug There is a EJB exception thrown....