You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Krishnakant Mane <co...@yahoo.co.uk> on 2005/04/02 21:21:24 UTC

connection pooling basic help please

hello,
I refered to the docs in tomcat 5 for connection
pooling.  the document is pritty comprehencive and I
understood the server.xml part of it.
but now I want to know how exactly can I use a
connection from the pool in my servlet.
the example in tomcat documentation is on a jsp based
applicatio.  but I don't understand how I use a pooled
connection in a servlet.
should I initialise the connection in the Init method?
 how and when should I close the connection?
and wat entries in the web.xml file will effect
connection pooling?
Please help it is really urgent.
thanks
Krishnakant.

Send instant messages to your online friends http://uk.messenger.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: connection pooling basic help please

Posted by Kwok Peng Tuck <pe...@gmail.com>.
Krishnakant Mane wrote:

>hello,
>I refered to the docs in tomcat 5 for connection
>pooling.  the document is pritty comprehencive and I
>understood the server.xml part of it.
>but now I want to know how exactly can I use a
>connection from the pool in my servlet.
>the example in tomcat documentation is on a jsp based
>applicatio.  but I don't understand how I use a pooled
>connection in a servlet.
>  
>
You use a pooled connection in a simillar manner to a driver managed 
connection, except that you look up a resource (JNDI in this case). In 
your servlet just look up the resource.

>should I initialise the connection in the Init method?
> how and when should I close the connection?
>  
>
You should close the connection immediately when you are done with it. 
Best not to pass references of them around. You would close them as a 
you would in a driver managed connection, that is Connection.close() ;

>and wat entries in the web.xml file will effect
>connection pooling?
>  
>
>Please help it is really urgent.
>thanks
>Krishnakant.
>
>Send instant messages to your online friends http://uk.messenger.yahoo.com 
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: connection pooling basic help please

Posted by QM <qm...@brandxdev.net>.
On Sat, Apr 02, 2005 at 08:21:24PM +0100, Krishnakant Mane wrote:
: the example in tomcat documentation is on a jsp based
: applicatio.  but I don't understand how I use a pooled
: connection in a servlet.
: [snip]
: should I initialise the connection in the Init method?
:  how and when should I close the connection?


1/ please post a *new* message when writing to the list.  Replying to
an old (unrelated) message confuses thread-aware mailers, which makes
your question harder to find (and thus answer).


2/ I don't have the JSP sample in front of me, but there should be
plenty of examples of using a DataSource out on the web.  A little
Googling should turn them up.  The short version is:
 - perform a JNDI lookup to find the DataSource
 - pull a Connection from that data source
 - use the Connection to talk with a databse
 - call close() on that connection

You should hold on to the Connection for as short a period of time as
possible.  This is easier to manage if all of the database calls are
done from a particular set of objects (a data layer).

Having all of your components do the JNDI lookup, etc can get messy and
tough to maintain.  Isolate all of your data calls to a separate object
(or set of objects).  You could initialize these objects in a
ServletContextListener and either store them under Application scope or
in a singleton such that they would be globally available.

-QM


-- 
software   -- http://www.brandxdev.net/
tech news  -- http://www.RoarNetworX.com/
code scan  -- http://www.JxRef.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org