Angus Mezick wrote:
> Interesting article, but how about using the JDBC connection pool class and
> is accessed by multiple servlets? Do you have to write something that will
> hold the pool? I know how to use an JNDI server for this but tomcat?
> --Angus
>
The approach I use is to store the connection pool object itself as a servlet
context attribute, which makes it easily accessible from any servlet or JSP page in
the same app. The Struts framework <http://jakarta.apache.org/struts> contains a
simple connection pool implementation that is automatically initialized for you in
this way.
Then, all you do when you need a connection is something like this:
ConnectionPool pool =
(ConnectionPool) getServletContext().getAttribute("pool");
Connection conn = null;
try {
conn = pool.getConnection();
... do whatever you need ...
... with this connection ...
} catch (SQLException e) {
... deal with exception ...
} finally {
if (conn != null)
conn.close();
}
Craig McClanahan
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets