You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Harald Ruf <ha...@on2trade.de> on 2000/06/20 17:54:27 UTC
Connection Pool with JavaServlet API 2.2
Hallo,
I have just upgrade my apache server from jserv to tomcat3.1. Now my connection pool, base on a servlet(this holds the connection to the database), doesn#t work because the 'getServlet()'-method (ServletContext) is now deprecated and always returns null. Have anybody another solution of connection pooling? Can anybody sen me a code example.
Thanks a lot
Harald
Re: Connection Pool with JavaServlet API 2.2
Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Jon Baer wrote:
> Just need clarification,
>
> So if not mistaken, this would occur inside the init() of your controller
> servlet, correct? And then made available to basically *everything* under it
> (via getAttribute())?
>
Yes, that's what I meant. You might also want to include code to gracefully shut
down the connection pool in the destroy() method of your controller servlet.
Servlet context attributes are available to all servlets and JSP pages within a
particular web application, but are not visible betwen different web applications
running in the same container.
>
> - Jon
>
> "Craig R. McClanahan" wrote:
>
> > ConnectionPool pool = new ConnectionPool( ... );
> > getServletContext().setAttribute("pool", pool);
>
Craig
Re: Connection Pool with JavaServlet API 2.2
Posted by Jon Baer <jo...@digitalanywhere.com>.
Just need clarification,
So if not mistaken, this would occur inside the init() of your controller
servlet, correct? And then made available to basically *everything* under it
(via getAttribute())?
- Jon
"Craig R. McClanahan" wrote:
> ConnectionPool pool = new ConnectionPool( ... );
> getServletContext().setAttribute("pool", pool);
Re: Connection Pool with JavaServlet API 2.2
Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Harald Ruf wrote:
> Hallo,I have just upgrade my apache server from jserv to tomcat3.1.
> Now my connection pool, base on a servlet(this holds the connection to
> the database), doesn#t work because the 'getServlet()'-method
> (ServletContext) is now deprecated and always returns null. Have
> anybody another solution of connection pooling? Can anybody sen me a
> code example. Thanks a lotHarald
The suggested approach is to store your connection pool object itself as
a servlet context attribute, like this:
ConnectionPool pool = new ConnectionPool( ... );
getServletContext().setAttribute("pool", pool);
Now, any servlet (or JSP page) in this web application can gain access
to the connection pool:
ConnectionPool pool =
(ConnectionPool) getServletContext().getAttribute("pool");
without needing to gain access to a servlet instance itself.
Craig McClanahan