commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Forbis <>
Subject RE: DBCP: Closed connections
Date Thu, 24 Apr 2003 15:48:41 GMT
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 {
    } catch (SQLException e) {
      System.err.println("Error on ResultSet close ("+e.toString()+")");
  if (stm!=null) {
    try {
    } catch (SQLException e) {
      System.err.println("Error on Statement close ("+e.toString()+")");
  if (conn!=null) {
    try {
    } 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;
  conn = myGetNewConnectionFromPoolCode();
  stm = conn.createStatement();
  rs = stm.executeQuery("some select query");
  while ({
    //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:
For additional commands, e-mail:

View raw message