db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <de...@segel.com>
Subject RE: Why close ResultSet & PreparedStatement?
Date Sat, 29 Nov 2008 22:53:07 GMT


> -----Original Message-----
> From: Mark Thornton [mailto:mthornton@optrak.co.uk]
> Sent: Saturday, November 29, 2008 4:42 PM
> To: Derby Discussion
> Subject: Re: Why close ResultSet & PreparedStatement?
> 
> derby@segel.com wrote:
> >> Amir Michail wrote:
> >>
> >>> Hi,
> >>>
> >>> Is there any point in calling the close method on ResultSet and the
> >>> close method of PreparedStatement?
> >>>
> >>> Amir
> >>>
> >>>
> >>>
> >> You might later change the database to one where it matters much more.
> >>
> >> Mark Thornton
> >>
> >
> > Huh?
> >
> > I'm sorry but your answer doesn't make any sense.
> >
> > To answer Amir's question... you close the ResultSet and the
> > PreparedStatements to remove any overhead as a result of their
> > instantiation.
> >
> >
> The resources required by an open ResultSet depend on the implementation
> of the database and drivers. It is fairly low for embedded Derby but
> considerably higher for some other databases. If there is a chance that
> the database used may be replaced by something else (Oracle, SQL Server,
> etc), then being careful about closing objects like ResultSet can be
> more important.
> 
> I agree that the overhead of PreparedStatement's is usually not great.
> 
> Mark Thornton

Ok...

With respect to *other* databases, you have timeouts which will drop the
database side of a result set or connection so the resources are recovered.
Commercial databases will clean things up. (Although its always better to
clean up your own mess) If you close the database connection, you'll trigger
the clean up process.

With respect to the prepared statements, its not an issue of overhead. Its
an issue of why one uses a prepared statement. The idea is that you prepare
a statement once, deal with the overhead and then reuse the statement
multiple times. 

Its not that you have "minimal" overhead, but that the concept is that
you're preparing a statement once to be used until your application
dies/ends/etc ...





Mime
View raw message