Fix [ 1874419 ] JDBC Statement not close in a finally block

Thanks Teo for remember this to me
This commit is contained in:
Carlos Ruiz 2008-01-26 18:44:44 +00:00
parent bc911ef263
commit 6b8491537c
1 changed files with 8 additions and 24 deletions

View File

@ -72,29 +72,21 @@ public class MRule extends X_AD_Rule
MRule retValue = null; MRule retValue = null;
String sql = "SELECT * FROM AD_Rule WHERE Value=? AND IsActive='Y'"; String sql = "SELECT * FROM AD_Rule WHERE Value=? AND IsActive='Y'";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, null); pstmt = DB.prepareStatement (sql, null);
pstmt.setString(1, ruleValue); pstmt.setString(1, ruleValue);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
if (rs.next ()) if (rs.next ())
retValue = new MRule (ctx, rs, null); retValue = new MRule (ctx, rs, null);
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log(Level.SEVERE, sql, e); s_log.log(Level.SEVERE, sql, e);
} }
try finally {
{ DB.close(rs, pstmt);
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null; pstmt = null;
} }
@ -117,31 +109,23 @@ public class MRule extends X_AD_Rule
MRule rule = null; MRule rule = null;
String sql = "SELECT * FROM AD_Rule WHERE EventType=? AND IsActive='Y'"; String sql = "SELECT * FROM AD_Rule WHERE EventType=? AND IsActive='Y'";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, null); pstmt = DB.prepareStatement (sql, null);
pstmt.setString(1, EVENTTYPE_ModelValidatorLoginEvent); pstmt.setString(1, EVENTTYPE_ModelValidatorLoginEvent);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) { while (rs.next ()) {
rule = new MRule (ctx, rs, null); rule = new MRule (ctx, rs, null);
rules.add(rule); rules.add(rule);
} }
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log(Level.SEVERE, sql, e); s_log.log(Level.SEVERE, sql, e);
} }
try finally {
{ DB.close(rs, pstmt);
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null; pstmt = null;
} }