Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 55760B5D80A for ; Wed, 8 Jun 2011 15:33:12 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 03163-08 for ; Wed, 8 Jun 2011 18:33:05 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp108.prem.mail.ac4.yahoo.com (smtp108.prem.mail.ac4.yahoo.com [76.13.13.47]) by mail.postgresql.org (Postfix) with SMTP id 0D001B5DBE7 for ; Wed, 8 Jun 2011 15:33:04 -0300 (ADT) Received: (qmail 59715 invoked from network); 8 Jun 2011 18:33:03 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:From:To:Cc:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=wtEUo/rcA88Z22wlh9ruwVMwFLf+BlCIfzbhwtkCwytEutBswlKZm7hPI5MnKxLzAV2ehCtARJvMr59rXcbp5uPGOdujY5wyvaV/dBBnmDddiKebkmeRusj4owO67ANq21jKkhh/gR3pge1oRbQw9Tu1Unm48aUCdOCrq6XtXvA= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1307557983; bh=QxvCJ8ct+gtTv8Ca1R4BpXEF0N12ZqFcKurbKa6Z73c=; h=Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:From:To:Cc:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=ypeOWba8xhpHBKIGex/OR9HXlgRlnVvh/r4UwHAvyfjBGjp38uK6O8v8W3uObJt2+RKzBXz7S+PTOBFAmygl8cNHhMFPE9IuW9zbPikgDEiEnE7Lxn7CwP/rWArJ//i1kcXWhPU8ueapo/LxcoKRs43C3QA8Dd3UW5lttXpN8ck= Received: from WolfDog (polobo@66.67.24.143 with login) by smtp108.prem.mail.ac4.yahoo.com with SMTP; 08 Jun 2011 11:33:03 -0700 PDT X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- X-YMail-OSG: s2HJ9gUVM1llT7uK_bReP5ZrWocATZQkuTOYNVxcIVyISds RrRqL7HpZ3u29AQOfOPewa3KEN2W5N9AUXgEAVnfq_q0iM9krMk1EGCn7QhY FFyPfFGPNTBwoP9KxKLKrT4MGDyh.Bjbdc.Jc9kRs.vKR6XMlsC5DTgwyaIi GpSV0z8aw7_nJ94vksAlVuAywDpgnoTaC5JExE9bzj89oce0t07cO2XlrH_p PjUp0oqkKXRQqM.ViSIN6atGRht8gaymMt1Po37StxP_Iwp3Yaj7Tt4gx74M bnwvmKpBGHvA3eX.gcShinhvTNVZSlcwM0NyXV4P5Ga_PuhkPvQuJcODymHs wvpbHSqtxTVCDcFgd49gKsQ-- X-Yahoo-Newman-Property: ymail-3 From: "David Johnston" To: Cc: References: In-Reply-To: Subject: Re: PGPoolingDataSource problem. Date: Wed, 8 Jun 2011 14:32:55 -0400 Message-ID: <02f801cc260a$7c0df640$7429e2c0$@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQKhloT9chgAaEsfcF57u8Dx+31fzZMI4sWg Content-Language: en-us X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.907 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RFC_ABUSE_POST=0.001, T_RP_MATCHES_RCVD=-0.01, UNPARSEABLE_RELAY=0.001 X-Spam-Level: X-Archive-Number: 201106/16 X-Sequence-Number: 21940 You have two major programming issues: 1) You ignore exceptions 2) You use static variables / singleton pattern without understanding Get yourself a good debugger, where you can step through the code line-by-line, and watch what happens to various "connection" variables during your two procedures. It will be obvious why and where you "released" the original connection without closing it. See notes below (in bold) to help you figure out where to focus your efforts. David J. From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Benjamin.Galaviz@LSGSkyChefs.com Sent: Wednesday, June 08, 2011 1:37 PM To: pgsql-jdbc@postgresql.org Subject: [JDBC] PGPoolingDataSource problem. private static Connection conn = null; public Connection getConnection(){ ---- You are returning a static variable from a non-static method... PGPoolingDataSource pgdb = (PGPoolingDataSource)getInstance(); conn = null; ---- and what if there was already another connection present.. try{ conn = pgdb.getConnection(); }catch(Exception e){ e.printStackTrace(); } return conn; } public static void closeConnection(){ if (conn != null){ try{conn.close();conn = null;}catch(Exception e){} ---- NEVER IGNORE EXCEPTIONS; ESPECIALLY CATCH (Exception e) } } try{DatabasePool.closeConnection();db=null;}catch(Exception e){} ---- NEVER IGNORE EXCEPTIONS; ESPECIALLY CATCH (Exception e) !!!!!! You are likely capturing - then ignoring - a NullPointerException here !!!!!!!!! Private String getValue(String XX){ PreparedStatement ps = db.getConnection().preparedStatement(sql); ResultSet rs = ps.executeQuery(); While (rs.next()){ retVal = rs.getString(1); } try{DatabasePool.closeConnection();db=null;}catch(Exception e){} } } --- Open and close within the same function is OK IF there was no connection already open String myValue = getValue(XX); ----Open and Close PreparedStatement ps = db.getConnection().preparedStatement(sql); --- Open try{DatabasePool.closeConnection();db=null;}catch(Exception e){} ----Close