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 1994611F60E7 for ; Thu, 27 Apr 2006 21:02:22 -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 62601-01 for ; Thu, 27 Apr 2006 21:02:14 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web54206.mail.yahoo.com (web54206.mail.yahoo.com [206.190.39.248]) by postgresql.org (Postfix) with SMTP id A827311F60E3 for ; Thu, 27 Apr 2006 21:02:12 -0300 (ADT) Received: (qmail 62616 invoked by uid 60001); 28 Apr 2006 00:02:09 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=1tHhamnisnDWokEnKeVHJMfgS2lfDS7UfbkX3rBqUXJOYRC7/NvQQwf9e5to5gi8ITG9wLe+3ai4M76B9pTXioz6JJilVSBytRYSkfM3qJu3vjKSkwi19zGMPqKszyVgpR7Cxj4E/jVhJXL73ge7HJlEM/8WTYuMLCeBKctuBZ0= ; Message-ID: <20060428000209.62614.qmail@web54206.mail.yahoo.com> Received: from [128.195.15.127] by web54206.mail.yahoo.com via HTTP; Thu, 27 Apr 2006 17:02:09 PDT Date: Thu, 27 Apr 2006 17:02:09 -0700 (PDT) From: "J." Subject: connection pooling with servlets To: pgsql-jdbc@postgresql.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1944875351-1146182529=:61641" Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200604/176 X-Sequence-Number: 15110 --0-1944875351-1146182529=:61641 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit 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. --0-1944875351-1146182529=:61641 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit 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. --0-1944875351-1146182529=:61641--