On 04/11/2010 15:41, Mikolaj Rydzewski wrote: > > On Thu, 4 Nov 2010 10:37:25 -0500, "Propes, Barry L " > <[email protected]> wrote: >> Not sure if it matters or not, but in your SponserSummaryDAO >> method, it appears you establish the rs as null, but don't ever close >> it? You might specifically try that. >> >> And is it necessary to reassign all those variables (connection, rs, >> pstmt) to null again in those catch blocks? > > One more reason to use well designed utilities like commons-dbutils or > jdbc-template. >
Or at least to use a static method to close the db objects & stop
putting the same boiler plate in all of the finally blocks.
public class DB {
public static void close(ResultSet obj) {
if (obj == null)
return;
try {
obj.close();
}
catch (SQLException e) {
// catch or log
e.printStackTrace();
}
}
public static void close(Statement obj) {
if (obj == null)
return;
try {
obj.close();
}
catch (SQLException e) {
// catch or log
e.printStackTrace();
}
}
public static void close(Connection obj) {
if (obj == null)
return;
try {
obj.close();
}
catch (SQLException e) {
// catch or log
e.printStackTrace();
}
}
}
ResultSet rs = null;
PreparedStatement ps = null;
Connection cn = null;
try {
// ... do DB stuff
}
catch (SQLException e) {
// ... log or something
}
finally {
DB.close(rs);
DB.close(ps);
DB.close(cn);
}
p
0x62590808.asc
Description: application/pgp-keys
signature.asc
Description: OpenPGP digital signature
