Wow.  Million different way for doing it.  Here's mine:

I use single dispatcher servlet that hands off requests to worker classes.  In this
servlet's init method I create one instance of DBConnection and put into services
hashtable to be passed to worker classes.

DBConnection in its constructor creates the pool and initializes it.  This is done
only once throughout the life of the servlet.

When request for searching for example comes in, the servlet detects which worker to
employ, gets the worker out of its postWorkers for example if it was a POST request,
and gives it the request, response and services hashtable.

The worker reads the request, constructs the query, gets the DBConnection out of the
services hashtable and does DBConnection.search(query).

DBConnection in its search method gets new connection from pool and executes the
query.  Then it returns the connection and returns the results that have been
cleanly put into a wrapping bean.

The worker possibly does something with the bean, then takes a jsp file and forwards
to it for display.

dave.

Ravi K U wrote:

> Yap!, if you are creating the new instance of a DbBroker obviously it will be
> create new instance for every other servlet( i mean Servlet A and Servlet B). So
> have a wrapper over the DbConnection and use a singleton pattern
>    regards
>      ravi
>
> 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
>
> ___________________________________________________________________________
> 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

--
David Mossakowski              [EMAIL PROTECTED]
Programmer                           212.310.7275
Instinet Corporation

"I don't sit idly by, I'm planning a big surprise"

___________________________________________________________________________
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

Reply via email to