Re: connection pooling with servlets - Mailing list pgsql-jdbc

From David Durham
Subject Re: connection pooling with servlets
Date
Msg-id 4451A813.6030403@vailsys.com
Whole thread Raw
In response to Re: connection pooling with servlets  ("J." <sweepingoar@yahoo.com>)
Responses Re: connection pooling with servlets  ("J." <sweepingoar@yahoo.com>)
List pgsql-jdbc
J. wrote:
> Thanks for replying.  I'm not sure if that would help, but maybe if I
> understand the suggestion better it will.
>
> Right now I've got the index.jsp calling Login servlet via POST.  Then
> Login creates the connection, puts it into a session with some other
> attributes and forward(req,res) to welcome.jsp.

Not much point in storing a datasource as a session attribute (1 datasource per application user?).  More appropriate
tomake it application-wide by putting a datasource in a servlet context or, as someone else suggested, a static
attribute/property/member/variable...  request.getSession().getServletContext().setAttribute(...).  JNDI is another
goodplace to put this sort of thing.  An easy way to make sure your datasource is always available is to use a servlet
contextlistener to create it when the application is initialized.  Google for servlet context lifecycle should tell you
howto do setup a listener. 

Now, as for a null pointer on your connection object, maybe you have something misconfigured in your datasource.
Username,password, host, and driver class are usual suspects. 


> Welcome.jsp has a form
> that uses GET to call a Search servlet and this is where I get a null
> pointer on the connection object.  I'm trying to get the session out of
> the request object, but it seems like the request loses state by the
> time I'm getting to it (in Search servlet).

Not sure.  You can post your code and maybe get some help.  Wait, is this homework?


-Dave


pgsql-jdbc by date:

Previous
From: Kris Jurka
Date:
Subject: Re: Bug with callable statement and output parameters
Next
From: "J."
Date:
Subject: Re: connection pooling with servlets