I can only agree - especially when you work with connection pools (and I hope you do),
as it's then the pools responsibility to close all statements, when you call
connection.close().
Just like Rich says: don't rely on it. Go the extra mile and practice programming
defensively and you potentially save days of debugging.
-hendrik
> -----Ursprungliche Nachricht-----
> Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Auftrag von Richard O. Hammer
> Gesendet: Mittwoch, 23. Juni 2004 10:21
> An: Research Triangle Java User's Group mailing list.
> Betreff: Re: [Juglist] Should I explicitly close ResultSet and
> Statements?
>
>
> From what I have picked up, when a Statement is closed it is supposed
> to first close any ResultSets it has created. Similarly, when a
> Connection is closed, it is supposed to first close any Statements it
> has created. So -- as long as these "shoulds" hold -- you should be
> able to get by with closing only the connection.
>
> But the class which you are using to implement one of these interfaces
> (Connection or Statement) comes, if I am not mistaken, in the specific
> JDBC driver which you have gotten for your database. It probably does
> not come from Sun. You may not have a reliable guarantee that the
> "shoulds" have been done. I have seen stories of memory leaks, of
> cases where "should" close has not happened, and something broke.
>
> Rich Hammer
>
> Tony Spencer wrote:
> > Is it necessary to close a ResultSet and PreparedStatement at the end of
> > some JDBC code before closing the Connection or are they closed
> > automatically by closing the database connection?
> >
> > For example is this ok?
> >
> > Connection conn = DbPool.getConnection();
> > ResultSet rs = null;
> > PreparedStatement = null;
> > .
> > .
> > .
> > conn.close();
> >
> >
> > Or should I do this?
> >
> > Connection conn = DbPool.getConnection();
> > ResultSet rs = null;
> > PreparedStatement = null;
> > .
> > .
> > .
> > rs.close();
> > stmnt.close();
> > conn.close();
>
>
> _______________________________________________
> Juglist mailing list
> [EMAIL PROTECTED]
> http://trijug.org/mailman/listinfo/juglist_trijug.org
_______________________________________________
Juglist mailing list
[EMAIL PROTECTED]
http://trijug.org/mailman/listinfo/juglist_trijug.org