X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 7CB3F11F6694 for ; Thu, 27 Apr 2006 21:59:30 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 63298-10 for ; Thu, 27 Apr 2006 21:59:21 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web54213.mail.yahoo.com (web54213.mail.yahoo.com [206.190.39.46]) by postgresql.org (Postfix) with SMTP id CD59811F61E8 for ; Thu, 27 Apr 2006 21:59:18 -0300 (ADT) Received: (qmail 94722 invoked by uid 60001); 28 Apr 2006 00:59:15 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=ytxcIcbREvLJR1EUBavmqw6LxdJFLYSZUjqfzndXC4CXlT2G+hjSXWNdsQD+7kVlOELRL2v4v4u2vJCY5/jwpJdJ3X1QgXDt0w1Zn0NrnwjjNWHhyRacStzsANKoGv1KhdYqS+3qUYvzJ5kooACQSIeG6mvJD89yegwMtnaXQu8= ; Message-ID: <20060428005915.94720.qmail@web54213.mail.yahoo.com> Received: from [128.195.15.127] by web54213.mail.yahoo.com via HTTP; Thu, 27 Apr 2006 17:59:15 PDT Date: Thu, 27 Apr 2006 17:59:15 -0700 (PDT) From: "J." Subject: Re: connection pooling with servlets To: pgsql-jdbc@postgresql.org In-Reply-To: <2F891858-CC29-433D-B89F-56843A5127EF@fastcrypt.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-125846432-1146185955=:94160" Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200604/178 X-Sequence-Number: 15112 --0-125846432-1146185955=:94160 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit 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. 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). Dave Cramer wrote: Use a static method to get the connection instead of the session. Dave On 27-Apr-06, at 8:02 PM, J. wrote: I am a novice, but thought it would make more sense to post this here.� I'm trying to write a basic webstore app for a school project and I'm having trouble getting more than one servlet to access the database connection.� I tried the method described on the PostgreSQL site - as I understood it.� That entailed opening a connection in one servlet and then having code like this in other servlets that need connections: ��� Connection grabConnection(HttpSession userSession){ ��� ��� ds = (Jdbc3PoolingDataSource) userSession.getAttribute("dSource"); ��� ��� Connection con = null; ��� ��� try { ��� ��� ��� con = ds.getConnection(); ��� ��� ��� // use connection ��� ��� } catch(SQLException e) { ��� ��� ��� // log error ��� ��� } finally { ��� ��� ��� if(con != null) { ��� ��� ��� ��� try {con.close();}catch(SQLException e) {} ��� ��� ��� } ��� ��� } ��� ��� return con; ��� } The trouble is (I'm sure you see it already) that passing a dataSource object in a session doesn't seem to work.� If I don't have a dataSource, then I can't make a connection and if I try to create a new connection, I get the error that is something like "Connection with that name already exists".� Any help and I'd be gratefull.� Thanks. --------------------------------- Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great rates starting at 1�/min. --------------------------------- New Yahoo! Messenger with Voice. Call regular phones from your PC and save big. --0-125846432-1146185955=:94160 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit 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.  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).

Dave Cramer <pg@fastcrypt.com> wrote:
Use a static method to get the connection instead of the session.

Dave
On 27-Apr-06, at 8:02 PM, J. wrote:

I am a novice, but thought it would make more sense to post this here.� I'm trying to write a basic webstore app for a school project and I'm having trouble getting more than one servlet to access the database connection.� I tried the method described on the PostgreSQL site - as I understood it.� That entailed opening a connection in one servlet and then having code like this in other servlets that need connections:

��� Connection grabConnection(HttpSession userSession){
��� ��� ds = (Jdbc3PoolingDataSource) userSession.getAttribute("dSource");
��� ��� Connection con = null;

��� ��� try {
��� ��� ��� con = ds.getConnection();
��� ��� ��� // use connection
��� ��� } catch(SQLException e) {
��� ��� ��� // log error
��� ��� } finally {
��� ��� ��� if(con != null) {
��� ��� ��� ��� try {con.close();}catch(SQLException e) {}
��� ��� ��� }
��� ��� }
��� ��� return con;
��� }

The trouble is (I'm sure you see it already) that passing a dataSource object in a session doesn't seem to work.� If I don't have a dataSource, then I can't make a connection and if I try to create a new connection, I get the error that is something like "Connection with that name already exists".� Any help and I'd be gratefull.� Thanks.


Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great rates starting at 1�/min.



New Yahoo! Messenger with Voice. Call regular phones from your PC and save big. --0-125846432-1146185955=:94160--