[ 1874419 ] JDBC Statement not close in a finally block

This commit is contained in:
Heng Sin Low 2008-01-29 08:47:47 +00:00
parent 6a71c3de64
commit 860b4ede1e
5 changed files with 69 additions and 103 deletions

View File

@ -129,23 +129,16 @@ public class AcctProcessor extends AdempiereServer
countError++; countError++;
} }
rs.close(); rs.close();
pstmt.close();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql.toString(), e); log.log(Level.SEVERE, sql.toString(), e);
} }
if (pstmt != null) finally
{ {
try DB.close(pstmt);
{
pstmt.close();
}
catch (Exception e)
{
}
} }
// //
if (count > 0) if (count > 0)
{ {

View File

@ -270,20 +270,17 @@ public class AlertProcessor extends AdempiereServer
pstmt.close (); pstmt.close ();
pstmt = null; pstmt = null;
} }
catch (Exception e) catch (Throwable e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
error = e; if (e instanceof Exception)
error = (Exception)e;
else
error = new Exception(e.getMessage(), e);
} }
try finally
{ {
if (pstmt != null) DB.close(pstmt);
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
// Error occured // Error occured

View File

@ -116,13 +116,15 @@ public class RequestProcessor extends AdempiereServer
} }
} }
rs.close (); rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
finally
{
DB.close(pstmt);
}
m_summary.append("New Due #").append(count); m_summary.append("New Due #").append(count);
if (countEMails > 0) if (countEMails > 0)
m_summary.append(" (").append(countEMails).append(" EMail)"); m_summary.append(" (").append(countEMails).append(" EMail)");
@ -169,13 +171,15 @@ public class RequestProcessor extends AdempiereServer
} }
} }
rs.close (); rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
finally
{
DB.close(pstmt);
}
m_summary.append("New Overdue #").append(count); m_summary.append("New Overdue #").append(count);
if (countEMails > 0) if (countEMails > 0)
m_summary.append(" (").append(countEMails).append(" EMail)"); m_summary.append(" (").append(countEMails).append(" EMail)");
@ -224,12 +228,15 @@ public class RequestProcessor extends AdempiereServer
count++; count++;
} }
rs.close(); rs.close();
pstmt.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
finally
{
DB.close(pstmt);
}
m_summary.append("Alerts #").append(count); m_summary.append("Alerts #").append(count);
if (countEMails > 0) if (countEMails > 0)
m_summary.append(" (").append(countEMails).append(" EMail)"); m_summary.append(" (").append(countEMails).append(" EMail)");
@ -265,12 +272,15 @@ public class RequestProcessor extends AdempiereServer
count++; count++;
} }
rs.close(); rs.close();
pstmt.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
finally
{
DB.close(pstmt);
}
m_summary.append("Escalated #").append(count).append(" - "); m_summary.append("Escalated #").append(count).append(" - ");
} // Esacalate } // Esacalate
@ -316,29 +326,20 @@ public class RequestProcessor extends AdempiereServer
} }
} }
rs.close(); rs.close();
pstmt.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
finally
{
DB.close(pstmt);
}
m_summary.append("Inactivity #").append(count); m_summary.append("Inactivity #").append(count);
if (countEMails > 0) if (countEMails > 0)
m_summary.append(" (").append(countEMails).append(" EMail)"); m_summary.append(" (").append(countEMails).append(" EMail)");
m_summary.append (" - "); m_summary.append (" - ");
} // Inactivity } // Inactivity
//
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
} // processRequests } // processRequests
/** /**
@ -442,22 +443,14 @@ public class RequestProcessor extends AdempiereServer
count++; count++;
} }
rs.close (); rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log (Level.SEVERE, sql, e); log.log (Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(pstmt);
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
m_summary.append("Status Timeout #").append(count) m_summary.append("Status Timeout #").append(count)
@ -506,23 +499,16 @@ public class RequestProcessor extends AdempiereServer
failure++; failure++;
} }
rs.close (); rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log (Level.SEVERE, sql, e); log.log (Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(pstmt);
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
m_summary.append("Auto Change Request #").append(count); m_summary.append("Auto Change Request #").append(count);
if (failure > 0) if (failure > 0)
m_summary.append("(fail=").append(failure).append(")"); m_summary.append("(fail=").append(failure).append(")");
@ -578,20 +564,14 @@ public class RequestProcessor extends AdempiereServer
notFound++; notFound++;
} }
rs.close(); rs.close();
pstmt.close();
pstmt = null;
} }
catch (SQLException ex) catch (SQLException ex)
{ {
log.log(Level.SEVERE, sql, ex); log.log(Level.SEVERE, sql, ex);
} }
try finally
{
if (pstmt != null)
pstmt.close();
}
catch (SQLException ex1)
{ {
DB.close(pstmt);
} }
pstmt = null; pstmt = null;
// //

View File

@ -77,8 +77,12 @@ public class Scheduler extends AdempiereServer
log.log(Level.WARNING, process.toString(), e); log.log(Level.WARNING, process.toString(), e);
m_summary.append(e.toString()); m_summary.append(e.toString());
} }
finally
{
if (m_trx != null) if (m_trx != null)
m_trx.close(); m_trx.close();
}
// //
int no = m_model.deleteLog(); int no = m_model.deleteLog();
m_summary.append("Logs deleted=").append(no); m_summary.append("Logs deleted=").append(no);

View File

@ -105,13 +105,15 @@ public class WorkflowProcessor extends AdempiereServer
count++; count++;
} }
rs.close (); rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, "wakeup", e); log.log(Level.SEVERE, "wakeup", e);
} }
finally
{
DB.close(pstmt);
}
m_summary.append("Wakeup #").append(count).append (" - "); m_summary.append("Wakeup #").append(count).append (" - ");
} // wakeup } // wakeup
@ -149,26 +151,17 @@ public class WorkflowProcessor extends AdempiereServer
count++; count++;
} }
rs.close (); rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
m_summary.append("DynPriority #").append(count).append (" - "); finally
{
DB.close(pstmt);
}
// Clean-up m_summary.append("DynPriority #").append(count).append (" - ");
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
} // setPriority } // setPriority
@ -194,9 +187,10 @@ public class WorkflowProcessor extends AdempiereServer
+ " AND (wf.AD_WorkflowProcessor_ID IS NULL OR wf.AD_WorkflowProcessor_ID=?))"; + " AND (wf.AD_WorkflowProcessor_ID IS NULL OR wf.AD_WorkflowProcessor_ID=?))";
int count = 0; int count = 0;
int countEMails = 0; int countEMails = 0;
PreparedStatement pstmt = null;
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, null);
pstmt.setInt (1, m_model.getAlertOverPriority()); pstmt.setInt (1, m_model.getAlertOverPriority());
pstmt.setInt (2, m_model.getAD_WorkflowProcessor_ID()); pstmt.setInt (2, m_model.getAD_WorkflowProcessor_ID());
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();
@ -217,6 +211,10 @@ public class WorkflowProcessor extends AdempiereServer
{ {
log.log(Level.SEVERE, "(Priority) - " + sql, e); log.log(Level.SEVERE, "(Priority) - " + sql, e);
} }
finally
{
DB.close(pstmt);
}
m_summary.append("OverPriority #").append(count); m_summary.append("OverPriority #").append(count);
if (countEMails > 0) if (countEMails > 0)
m_summary.append(" (").append(countEMails).append(" EMail)"); m_summary.append(" (").append(countEMails).append(" EMail)");
@ -258,13 +256,16 @@ public class WorkflowProcessor extends AdempiereServer
count++; count++;
} }
rs.close (); rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, "(EndWaitTime) - " + sql, e); log.log(Level.SEVERE, "(EndWaitTime) - " + sql, e);
} }
finally
{
DB.close(pstmt);
}
m_summary.append("EndWaitTime #").append(count); m_summary.append("EndWaitTime #").append(count);
if (countEMails > 0) if (countEMails > 0)
m_summary.append(" (").append(countEMails).append(" EMail)"); m_summary.append(" (").append(countEMails).append(" EMail)");
@ -311,24 +312,15 @@ public class WorkflowProcessor extends AdempiereServer
{ {
log.log(Level.SEVERE, "(Inactivity): " + sql, e); log.log(Level.SEVERE, "(Inactivity): " + sql, e);
} }
finally
{
DB.close(pstmt);
}
m_summary.append("Inactivity #").append(count); m_summary.append("Inactivity #").append(count);
if (countEMails > 0) if (countEMails > 0)
m_summary.append(" (").append(countEMails).append(" EMail)"); m_summary.append(" (").append(countEMails).append(" EMail)");
m_summary.append (" - "); m_summary.append (" - ");
} // Inactivity } // Inactivity
// Clean-up
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
} // sendAlerts } // sendAlerts
/** /**