Re: What happens to a ResultSet when statement closed

From: Kris Jurka <books(at)ejurka(dot)com>
To: Warren Little <wlittle(at)securitylending(dot)com>
Cc: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: What happens to a ResultSet when statement closed
Date: 2004-01-12 22:21:54
Message-ID: Pine.LNX.4.33.0401121715320.14164-100000@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Mon, 12 Jan 2004, Warren Little wrote:

> Consider the following code
> ....
> ResultSet r = statement.executeQuery();
> statement.close();
> connection.close();
>
> What happens to the ResultSet r?
> What happens if I only close the statement, but continue to use
> the connection?
>

Calling close on the Statement calls close on the ResultSet. That said
calling close on the ResultSet only discards the reference to the data
retrieved, so a number of methods can still be called on it even though it
is closed (getFetchDirection is an example if a rather useless one.) This
isn't strictly spec compliant, but it seems like a waste to add an
isClosed check to every method.

Calling close on a Connection does not close Statements and ResultSets
that it produced although it should. Again these objects are largely
useless without the connection and the theory is that things should fall
out of scope and be garbage collected. This seems like a potentially more
serious problem because you could have still have a reference to a very
large ResultSet that was not closed which could take up a fair amount of
memory.

Kris Jurka

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Andrew Rawnsley 2004-01-12 22:29:23 Re: What happens to a ResultSet when statement closed
Previous Message Warren Little 2004-01-12 22:11:43 What happens to a ResultSet when statement closed