But the code you posted does not create a new DataSource object. It just gets a reference to an existing one stored in JNDI. Nothing new about the DataSource object. Note the lack of a new operator.

--David

Rashmi Rubdi wrote:

On 4/27/07, albrecht andrzejewski <[EMAIL PROTECTED]> wrote:


>> 3) In my servlet init(), I lookup the data-source. Each lookup essentially >> instantiates an instance of the data-source. So a connection pool gets
>> instantiated in each servlet's init.
>>
>> Now it doesn't make sense to create a new connection pool in each servlet. >> So I'd like to create a single connection pool that will be used by all >> servlets. I've been looking thru the tomcat docs, to see where I could >> create this central resource for my webapp. The only option I've seen so far >> is to create my own life-cycle listener for my webapp. That way I can create >> a connection pool on start-up. I was wondering if there was a better way to
>> do this ?

It's actually your container which create the connection pool and not
your servlet. What you do when you are looking up is just finding a
reference to the pre-existing datasource. So don't worry


Hi Ali,

Thank you for the above post, I agree with it.

Normally one has to write the following lines to get the database
connection from the connection pool:

        Context initContext = new InitialContext(); //(1)
Context envContext = (Context)initContext.lookup("java:/comp/env"); //(2) DataSource ds = (DataSource)envContext.lookup("jdbc/TestDB"); //(3)
        conn = ds.getConnection(); //(4)

I think most people try to initialize the DataSource object in the
above code, when Tomcat starts up and they only wan to get the ds
object in a DAO class before creating a new connection from the
connection pool.

I think Srinivas wants to create the ds object when Tomcat starts up
and re-use the ds object in the DAO class instead of re-creating it
each time he needs it inside a DAO.

and please do
not write your own lifecycle :-)

Regards, Ali.


-Regards
Rashmi

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to