On , Dimitris Tsirikos <[EMAIL PROTECTED]> wrote:


>
>When I was refering to getting a connection I meant the
>DriverManager.getConnection(...) method. When you say "and then reopen it in
>ejbActivate()" are you reffering to the getConnection method? If that is so
>then this is the worst-case scenario in terms of efficiency. The ideal case for
>me would be to get the connection in a default constructor (the container calls
>newInstance() on the bean class and that in turn calls the default constructor)
>if you know to what database to connect to as in:
>public class MyBean
>{
>    Connection con = null;
>
>    public MyBean()
>    {
>        ...
>        con = DriverManager.getConnection("jdbc:odbc:Golf","", ""); //connect
>to database Golf using the default jdbc driver
>    }
>}
>
>and then invoke createStatement on the connection to do whatever you want. Like
>this there would only be 50 (see previous email) connections created for as
>long as the container lives.
>If you do not know beforehand the database to connect to (more general case)
>then get the connection inside the ejbCreate method. All this refers to
>container-managed beans.That is why I see no reason to open and close the
>connection in the ejbActivate/ejbPassivate methods. Let the server do all the
>work.
>

Hi,

I am not really sure if you would want to get the connection in the constructor
of the bean. According to my understanding, there is a case where it is not
necessary for the container to call the ejbcreate atall ( in case of stateless
session beans) which means that there may be no calls to the constructor of a
stateless session bean. Since the stateless session bean doesnot maintain state
between calls, the next call to the existing statelss session bean will not have
this connection variable at all eventhough it is a member variable ( there is a
possibility of the connection being left unclosed which mean soon we will end up
with no more db connections left in the pool). The stateless session bean
doesnot maintain states is the reason why we cannot use initialisation
parameters in the ejbcreate method.

Correct me if I am wrong.

Thanks
Uma

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