-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Josh,
On 10/30/2009 2:42 PM, Josh Gooding wrote:
> I also found this tid bit lying around. It get's a connection, but doesn't
> close the statement.
Might I suggest the following changes:
> public static void closeResources(ResultSet rs) throws
> AardvarkResourceException {
Statement s = null;
Connection c = null;
> try {
s = rs.getStatement();
> if (s != null) { // ResultSets produced by metadata queries do
> not have associated statements
// The previous comment is false. :(
c = s.getConnection();
> //s.close();
> //c.close();
// ConnectionPool.recycleConnection(c);
> }
// rs.close();
> } catch (SQLException e) {
> throw new AardvarkResourceException("Error closing resources
> associated with ResultSet", e);
> }
finally
{
if(null != rs) try { rs.close(); }
catch (SQLException sqle)
{ sqle.printStackTrace(); /* or other logger */ }
if(null != s) try { s.close(); } catch (SQLException sqle)
{ sqle.printStackTrace(); /* or other logger */ }
if(null != c)
ConnectionPool.recycleConnection(c);
// Note that if you're using DBCP or really any decent
// connection pool, you can just call Connection.close()
// and it goes back to the pool itself.
}
> It still doesn't close the statement, but closes the connection leaving the
> statement hanging.... I'll fix and make sure to use it.
I would dump this method unless it's being widely used. If it's being
widely used, I'd fix it as shown above. Remember: finally blocks are the
way to go, here.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkrrPMQACgkQ9CaO5/Lv0PCL1ACfb3GzBOkJUnOErod9W2JDwnq2
f4kAn3xkTgWVgWe3P/LTqBs6SMLDDu/k
=9KTw
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]