*BF [ 1874419 ] JDBC Statement not close in a finally block

organize imports
This commit is contained in:
Redhuan D. Oon 2008-02-19 10:37:36 +00:00
parent 24c5b135f4
commit 2e6f00dc7e
1 changed files with 23 additions and 28 deletions

View File

@ -16,11 +16,18 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.process; package org.compiere.process;
import java.sql.*; import java.sql.PreparedStatement;
import java.util.logging.*; import java.sql.ResultSet;
import java.util.logging.Level;
import org.compiere.model.*; import org.compiere.model.MFactAcct;
import org.compiere.util.*; import org.compiere.model.MInvoice;
import org.compiere.model.MInvoiceTax;
import org.compiere.model.MTaxDeclaration;
import org.compiere.model.MTaxDeclarationAcct;
import org.compiere.model.MTaxDeclarationLine;
import org.compiere.util.AdempiereSystemError;
import org.compiere.util.DB;
/** /**
* Create Tax Declaration * Create Tax Declaration
@ -94,37 +101,31 @@ public class TaxDeclarationCreate extends SvrProcess
+ " AND NOT EXISTS (SELECT * FROM C_TaxDeclarationLine tdl " + " AND NOT EXISTS (SELECT * FROM C_TaxDeclarationLine tdl "
+ "WHERE i.C_Invoice_ID=tdl.C_Invoice_ID)"; + "WHERE i.C_Invoice_ID=tdl.C_Invoice_ID)";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
int noInvoices = 0; int noInvoices = 0;
try try
{ {
pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt.setTimestamp(1, m_td.getDateFrom()); pstmt.setTimestamp(1, m_td.getDateFrom());
pstmt.setTimestamp(2, m_td.getDateTo()); pstmt.setTimestamp(2, m_td.getDateTo());
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
create (new MInvoice (getCtx(), rs, null)); // no lock create (new MInvoice (getCtx(), rs, null)); // no lock
noInvoices++; noInvoices++;
} }
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(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
return "@C_Invoice_ID@ #" + noInvoices return "@C_Invoice_ID@ #" + noInvoices
+ " (" + m_noLines + ", " + m_noAccts + ")"; + " (" + m_noLines + ", " + m_noAccts + ")";
} // doIt } // doIt
@ -166,12 +167,13 @@ public class TaxDeclarationCreate extends SvrProcess
/** Acct **/ /** Acct **/
String sql = "SELECT * FROM Fact_Acct WHERE AD_Table_ID=? AND Record_ID=?"; String sql = "SELECT * FROM Fact_Acct WHERE AD_Table_ID=? AND Record_ID=?";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, null); pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, MInvoice.Table_ID); pstmt.setInt (1, MInvoice.Table_ID);
pstmt.setInt (2, invoice.getC_Invoice_ID()); pstmt.setInt (2, invoice.getC_Invoice_ID());
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
MFactAcct fact = new MFactAcct(getCtx(), rs, null); // no lock MFactAcct fact = new MFactAcct(getCtx(), rs, null); // no lock
@ -180,24 +182,17 @@ public class TaxDeclarationCreate extends SvrProcess
if (tda.save()) if (tda.save())
m_noAccts++; m_noAccts++;
} }
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(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
/** **/ /** **/
} // invoice } // invoice