Re: [Erserver-general] Why does Statement.close() close result set?

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>, erserver-general(at)svr3(dot)postgresql(dot)org
Subject: Re: [Erserver-general] Why does Statement.close() close result set?
Date: 2003-10-10 15:43:19
Message-ID: 1065800599.2159.171.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Tom,

this is what the spec says for Statement.close()

Releases this Statement object's database and JDBC resources immediately
instead of waiting for this to happen when it is automatically closed.
It is generally good practice to release resources as soon as you are
finished with them to avoid tying up database resources.

Note: A Statement object is automatically closed when it is garbage
collected. When a Statement object is closed, its current ResultSet
object, if one exists, is also closed

Dave

On Fri, 2003-10-10 at 11:21, Tom Lane wrote:
> I've been trying to get erserver to work with the current JDBC driver,
> and finding that it doesn't work very well. The problem is that there
> are many places in which a function creates a Statement, executes it
> to get a ResultSet, closes the Statement, and returns the ResultSet to
> its caller. This pattern worked okay in JDBC 7.0, but it fails
> completely with the current driver, because Statement.close() thinks
> it should close the last result set returned by the statement.
>
> I've been able to sort-of work around this by commenting out the
> explicit close calls, but this doesn't really work, because the
> created Statement object has no references once control has left
> the calling function. A garbage-collection pass would finalize the
> Statement and thereby zap the ResultSet, whether or not there are
> still any valid references to the ResultSet.
>
> The above programming pattern seems perfectly valid to me, and
> accordingly I think that Statement.close() is broken. The current
> behavior foregoes all the advantages of Java's memory management model
> and turns them into liabilities. Instead of letting garbage collection
> do what it's supposed to, the programmer is forced to hang onto
> references to one object in order to preserve the validity of a
> different object.
>
> Comments?
>
> regards, tom lane
>
> BTW, the error reported by ResultSet.next() in this situation is
> extremely misleading; it gripes about "connection closed" when it
> should say "result set closed".
> _______________________________________________
> Erserver-general mailing list
> Erserver-general(at)gborg(dot)postgresql(dot)org
> http://gborg.postgresql.org/mailman/listinfo/erserver-general
>
>

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Peter Kovacs 2003-10-10 15:46:20 Re: Why does Statement.close() close result set?
Previous Message Kevin Schmidt 2003-10-10 15:34:16 Re: Why does Statement.close() close result set?