pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: J. <sweepingoar@yahoo.com>
To: pgsql-jdbc@postgresql.org
Subject: connection pooling with servlets
Date: Thu, 27 Apr 2006 17:02:09 -0700 (PDT)
Message-ID: <20060428000209.62614.qmail@web54206.mail.yahoo.com> (raw)

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&cent;/min.

view thread (8+ messages)  latest in thread

Message-ID: <20060428000209.62614.qmail@web54206.mail.yahoo.com>
Permalink:  ../20060428000209.62614.qmail@web54206.mail.yahoo.com/
Also on:    postgresql.org/message-id/20060428000209.62614.qmail@web54206.mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: sweepingoar@yahoo.com
  Subject: Re: connection pooling with servlets
  In-Reply-To: <20060428000209.62614.qmail@web54206.mail.yahoo.com>
  References: <20060428000209.62614.qmail@web54206.mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox