Eric Lim wrote:
> Does anyone know how we can implement a Global JDBC Connection pool in JSDK
> 2.1 after the getServlet() method is removed??..
> This pool is supposed to be shared by all the servlets. I used to call
> getServlet() to get a reference to the DBServlet and then invoked the
> getConnection() method to get a free JDBC connection. But how do i achieve
> this with RequestDispatcher????
>
You don't need request dispatchers to share user data objects.
In your initialization servlet that creates the pool, store it in the servlet
context attributes, like this:
ConnectionPool pool = ....; // Appropriate setup stuff
getServletContext().setAttribute("pool", pool);
then, in any servlet that needs access to the connection pool to grab a
connection, do this:
ConnectionPool pool =
(ConnectionPool) getServletContext().getAttribute("pool");
Using servlet context attributes is very similar to storing user objects in an
HttpSession, except that they are shared across all the servlets (and JSP
pages) in your application, instead of being limited to one user.
You can also do this kind of sharing with statics, as others have suggested,
but there are some pretty good O-O design reasons that this should not be your
first choice.
>
> Cheers
> Eric
>
Craig McClanahan
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html