You can add the servlet to the servlet context from the ConnPoolServlet init() method as follows:
public void init(ServletConfig cfg) throws ServletException
{
super.init(cfg);
// Create our connection pool
_connPool = new ConnPoolServlet();
// Initialize the connection pool.
try {
_connPool.initialize();
} catch (Exception ex) {
ex.printStackTrace();
throw new ServletException ("Unable to initialize
connection pool");
}
// Add this servlet to the context
getServletContext().setAttribute("connpool", this);
}
You can then obtain a connection from another servlet by getting a reference to the ConnPoolServlet from the servlet context using the key "connpool" like this:
ConnPoolServlet servlet = (ConnPoolServlet)getServletContext().getAttribute("connpool");
-ernie
Stuart Norton wrote:
Hi,This is my first post on the list, so I've finally come out of the woodwork!
I'm using the com.javaexchange.dbConnectionPool class (from
www.javaexchange.com) to access a database through an ODBC driver. This
works with one servlet, where I define a new instance of the class in the
init() of my servlet, but I'm confused about what happens when I use another
servlet that needs to talk to the same DbConnectionPool class.The init() code in my second class contains the same code as the first (ie.
myBroker = new DbConnectionPool(...blah, blah..);), so I'm wondering whether
it's talking to the other instance from the first servlet, or making a new
instance.Can anyone please help me.
Stuart Norton,
Densitron Technologies plc, UK
e: [EMAIL PROTECTED]___________________________________________________________________________
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
begin:vcard n:Varitimos;Ernie tel;cell:781-929-3856 tel;home:781-784-1997 tel;work:781-784-3900 x-mozilla-html:TRUE url:http://www.skyserver.com org:Skyserver Consulting, Inc. adr:;;144 Upland Rd;Sharon;MA;02067; version:2.1 email;internet:[EMAIL PROTECTED] title:President fn:Ernie Varitimos end:vcard
