Hello team,
Can I use an instance variable to store jdbc connection that I got from datasource.getConnection? I get this connection in ejbCreate() and put this in instance variable. Is this ok? where should I close this connection? which method? I am using stateless SB. Also I want to use instance varible to store the local home to my entity bean in this stateless SB. Do I need to nullify these db connection and local home in any methods? Please clarify.
Thank you
-
jdbc connection from datasource in stateless session bean (3 messages)
- Posted by: sireesha beeram
- Posted on: October 07 2004 07:03 EDT
Threaded Messages (3)
- jdbc connection from datasource in stateless session bean by stephen smithstone on October 07 2004 08:48 EDT
- jdbc connection from datasource in stateless session bean by Paul Maessen on October 07 2004 15:19 EDT
- jdbc connection from datasource in stateless session bean by Igor Shindin on October 11 2004 10:00 EDT
-
jdbc connection from datasource in stateless session bean[ Go to top ]
- Posted by: stephen smithstone
- Posted on: October 07 2004 08:48 EDT
- in response to sireesha beeram
Hello team,Can I use an instance variable to store jdbc connection that I got from datasource.getConnection? I get this connection in ejbCreate() and put this in instance variable. Is this ok? where should I close this connection? which method? I am using stateless SB. Also I want to use instance varible to store the local home to my entity bean in this stateless SB. Do I need to nullify these db connection and local home in any methods? Please clarify.Thank you
obtain the reference to the datasource in the setSessionContext then open the connection when used in the method and then close the connection in a finally block in the method -
jdbc connection from datasource in stateless session bean[ Go to top ]
- Posted by: Paul Maessen
- Posted on: October 07 2004 15:19 EDT
- in response to sireesha beeram
Hi Sireesha,
The EJB spec states that access to resource managers from a stateless SB is restricted to businessmethods only. But it doesn't specify how the container should react if you chose to use ejbCreate to obtain a connection. So, even if the container allows it, it is not portable. You could define an instance variable that holds your connection factory, and initialize that the first time a BM is called. From within a BM use this factory to create a new connection, which you should destroy at the end of the method. -
jdbc connection from datasource in stateless session bean[ Go to top ]
- Posted by: Igor Shindin
- Posted on: October 11 2004 10:00 EDT
- in response to sireesha beeram
You have to get DataSource reference in the method setSessionContext().Open and close your connection in your business method. In this case you will have 100% garantee that connection was closed.