I am using the official mySql jdbc driver (MySQL Connector/J).  I don't
really trust it so I think I'll go through my code and make sure I've closed
everything myself.  From what yall have said it sounds like this would be
good practice in case I ever switch drivers and/or database.

T O N Y  S P E N C E R
Notsleepy LLC
6512 Six Forks Rd.
Suite 502-B 
Raleigh, NC 27615
Phone: 919.848.0691
Mobile: 415.637.6481
[EMAIL PROTECTED] 

  

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Richard O. Hammer
> Sent: Wednesday, June 23, 2004 10:21 AM
> To: Research Triangle Java User's Group mailing list.
> Subject: 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

Reply via email to