Return-Path: Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 58106 invoked from network); 25 Apr 2003 15:39:18 -0000 Received: from london-bridge.east.veritas.com (HELO rosmime01.veritas.com) (207.30.27.2) by daedalus.apache.org with SMTP; 25 Apr 2003 15:39:18 -0000 Received: from lmoxch04.veritas.com (unverified) by rosmime01.veritas.com (Content Technologies SMTPRS 4.3.6) with ESMTP id for ; Fri, 25 Apr 2003 11:39:18 -0400 Received: by lmoxch04.enterprise.veritas.com with Internet Mail Service (5.5.2656.59) id <2PYXG2SL>; Fri, 25 Apr 2003 11:39:18 -0400 Message-ID: <8BE017CC8923D511A00A0008C78605EE037B722C@lmoxch04.enterprise.veritas.com> From: Chris Forbis To: 'Jakarta Commons Users List' Subject: RE: DBCP: Closed connections Date: Fri, 25 Apr 2003 11:39:16 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2656.59) Content-Type: text/plain X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N I would agree it should be a waste, but after much testing with at least the Oracle 8i JDBC driver it does not. The resultSet is left open causing a cursor issue on the database. So for safety I got in the habit of always doing it. -----Original Message----- From: Hope, Matthew [mailto:Matthew.Hope@capitalone.com] Sent: Friday, April 25, 2003 3:43 AM To: 'Jakarta Commons Users List' Subject: RE: DBCP: Closed connections Statement.close() javadoc contract guarantees that it will cascade close() to the ResultSet... Closing them both seems a waste. Though it would protect you from a crappy implementation not obeying the contract... It is somewhat annoying that code of the form Statement s = conn.getConnection(); try { ... } catch (SQLException e) { ... } Finally { if (s != null) { try { s.close(); } catch (SQLException e) { // do nothing since we aren't interested } } } Exists everywhere. I tend to add 3 overloaded methods to some Database utility class Already in use in the application. Would be good to have these in some class so we wouldn't have to keep using them. (the boolean is just in case you really want to know if close() got called succesfully) public static boolean quickClose(Statement s) { if (s != null) { try { s.close(); return true; } catch (SQLException e) { // do nothing since we aren't interested } } return false; } Matt -----Original Message----- From: Chris Forbis [mailto:chris.forbis@veritas.com] Sent: 24 April 2003 16:49 To: 'Jakarta Commons Users List' Subject: RE: DBCP: Closed connections Yea that would be a major issue :) A procedure that is good to have around :) //Feel free to pass null in when they are not needed... public static void closeDatabaseObjects( Connection conn, Statement stm, ResultSet rs) { if (rs!=null) { try { rs.close(); } catch (SQLException e) { System.err.println("Error on ResultSet close ("+e.toString()+")"); } } if (stm!=null) { try { stm.close(); } catch (SQLException e) { System.err.println("Error on Statement close ("+e.toString()+")"); } } if (conn!=null) { try { conn.close(); } catch (SQLException e) { System.err.println("Error on Connection close ("+e.toString()+")"); } } } -- a use of this -- Conenction conn = null; Statement stm = null; ResultSet rs = null; try{ conn = myGetNewConnectionFromPoolCode(); stm = conn.createStatement(); rs = stm.executeQuery("some select query"); while (rs.next()){ //do stuff with the result } } catch (SQLException e) { //Some error code } finally { closeDatabaseObjects( conn, stm, rs ); //or just closeDatabaseObjects( null, stm, rs); if you don't want to close the database Connection } -----Original Message----- From: Behrens Matt - Grand Rapids [mailto:Matt.Behrens@Kohler.Com] Sent: Thursday, April 24, 2003 7:25 AM To: Jakarta Commons Users List Subject: Re: DBCP: Closed connections Chris Forbis wrote: > Don't know if this is your issue but I had the same issue and it took me > forever to track down... It all came back to the following code... > > //Stm = Statement > //Rs = ResultSet > > stm.close(); > rs.close(); > > The problem was simple, because of the order of these is wrong the > connection pool got messed up bad. > > Had to change to > rs.close(); > stm.close(); > > and all started working fine... I don't close my ResultSets or Statements -- just the connections. I suppose this could be a problem, actually. I don't know. I've had a few little issues like that. Most memorable was when I had inexplicable hangs (this is an interactive server app where the users come in via telnet), and I beat my head against the wall for a little bit before I realized I was just running out of connections because I never explicitly returned a few to the pool... --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org ************************************************************************** The information transmitted herewith is sensitive information intended only for use by the individual or entity to which it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer. --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org