Search code examples
javasqldatabasedatasourceresultset

Why are connections not getting closed?


I have a code where I am connecting to db using a resultset and then after getting the necessary values closing the connection in finally block.

But for some reason the query is still running and the connection pool is not release. Can someone help here.

try {
 rsU = dbAccess.query(FasoCommon.sqlUpdatable, params, true);
if (rsU.next()) {
            updatable = rsU.getString("UpdatableFields");
            logger.info("UpdatableFields:: "+updatable);

            }
        }
finally {
        close(rsU, null, null);

}

private void close(ResultSet rs, Statement stmt, Connection conn) {
    if (rs != null) {
        try {
            rs.close();
            rs=null;
            //logger().info("ResultSet Closed : " + rs);
        } catch (SQLException e) {
            //logger().error("The result set cannot be closed.", e);
        }
    }
    if (stmt != null) {
        try {
            stmt.close();
            stmt=null;
            //logger().info("Statement Closed : " + stmt);
        } catch (SQLException e) {
            //logger().error("The statement cannot be closed.", e);
        }
    }
    if (conn != null) {
        try {
            conn.close();
            conn=null;
            //logger().info("Data Source Connection Closed : " + conn);
        } catch (SQLException e) {

        }
    }
} 

Solution

  • there was an set object which was keeping the refence to the connection even after closing the connection.Fixing that part resolved the issue.