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

organize imports
This commit is contained in:
Redhuan D. Oon 2008-07-04 03:39:24 +00:00
parent f6e16856c9
commit 01a63d62dc
5 changed files with 120 additions and 171 deletions

View File

@ -13,13 +13,17 @@
*****************************************************************************/
package org.compiere.FA;
import java.sql.*;
import org.compiere.process.*;
//import org.compiere.model.X_C_Period;
import org.compiere.model.*;
import org.compiere.util.DB;
//import java.math.*;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.compiere.model.MAssetChange;
import org.compiere.model.MRefList_Ext;
import org.compiere.model.X_A_Asset_Transfer;
import org.compiere.model.X_A_Depreciation_Exp;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
/**
* Asset Transfer
@ -86,7 +90,7 @@ public class AssetTransfer extends SvrProcess
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sql,null);
log.info("doIt - SQL=" + sql);
ResultSet rs = null;
//X_A_Depreciation_Exp depexp = new X_A_Depreciation_Exp (getCtx(), 0, null);
String clientCheck = " AND AD_Client_ID=" + AssetTransfer.getAD_Client_ID();
@ -102,7 +106,7 @@ public class AssetTransfer extends SvrProcess
}
try {
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
if (AssetTransfer.isA_Transfer_Balance_IS()==true)
{
while (rs.next());
@ -132,25 +136,16 @@ public class AssetTransfer extends SvrProcess
depexp1.setA_Period(AssetTransfer.getC_Period_ID());
depexp1.setA_Entry_Type("TRN");
depexp1.save();
}
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.info("getDeliveries"+ e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
sql = null;
@ -166,7 +161,7 @@ public class AssetTransfer extends SvrProcess
pstmt = DB.prepareStatement (sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE,null);
try {
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
rs.first();
X_A_Depreciation_Exp depexp2 = new X_A_Depreciation_Exp (getCtx(), 0, null);
@ -263,25 +258,15 @@ public class AssetTransfer extends SvrProcess
// Remove Entry from Processing file
rs.close();
pstmt.close();
pstmt = null;
}
}
catch (Exception e)
{
log.info("TransferAssets"+ e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return "";
} // doIt

View File

@ -13,12 +13,12 @@
*****************************************************************************/
package org.compiere.FA;
import java.sql.*;
//import java.text.SimpleDateFormat;
//import java.util.Date;
import java.util.GregorianCalendar;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Calendar;
import org.compiere.util.*;
import java.util.GregorianCalendar;
import org.compiere.util.DB;
/**
* Fixed Asset Conventions
@ -77,8 +77,9 @@ public class Conventions {
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sqlB.toString(),null);
ResultSet rs = null;
try {
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
while (rs.next()){
Calendar calendar = new GregorianCalendar();
calendar.setTime(rs.getDate("ASSETSERVICEDATE"));
@ -111,16 +112,9 @@ public class Conventions {
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return v_adj;
}

View File

@ -13,12 +13,21 @@
*****************************************************************************/
package org.compiere.FA;
import java.sql.*;
import org.compiere.model.*;
import org.compiere.process.*;
import org.compiere.util.DB;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.compiere.model.MAssetAcct;
import org.compiere.model.MAssetChange;
import org.compiere.model.MRefList_Ext;
import org.compiere.model.X_A_Asset;
import org.compiere.model.X_A_Asset_Addition;
import org.compiere.model.X_A_Asset_Group_Acct;
import org.compiere.model.X_A_Depreciation_Workfile;
import org.compiere.model.X_GL_JournalLine;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
/**
* Create Asset from FA GL Process
@ -59,17 +68,18 @@ public class CreateGLAsset extends SvrProcess
protected String doIt() throws java.lang.Exception
{
log.info("Starting inbound invoice process");
int uselifemonths = 0;
int uselifeyears = 0;
// int uselifemonths = 0;
// int uselifeyears = 0;
String sql =" SELECT * FROM GL_JOURNALLINE WHERE A_Processed <> 'Y' and AD_Client_ID = ?"
+ " and A_CreateAsset = 'Y' and Processed = 'Y'";
log.info(sql);
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement(sql,get_TrxName());
ResultSet rs = null;
try {
pstmt.setInt(1, p_client);
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
while (rs.next()){
@ -137,8 +147,8 @@ public class CreateGLAsset extends SvrProcess
asset.setIsDepreciated(true);
asset.setIsOwned(true);
asset.save();
uselifemonths = assetgrpacct.getUseLifeMonths();
uselifeyears = assetgrpacct.getUseLifeYears();
// uselifemonths = assetgrpacct.getUseLifeMonths();
// uselifeyears = assetgrpacct.getUseLifeYears();
}
else if(asset.getUseLifeMonths() == 0){
@ -147,13 +157,14 @@ public class CreateGLAsset extends SvrProcess
asset.setIsDepreciated(true);
asset.setIsOwned(true);
asset.save();
uselifemonths = asset.getUseLifeYears()*12;
uselifeyears = asset.getUseLifeYears();
// uselifemonths = asset.getUseLifeYears()*12;
// uselifeyears = asset.getUseLifeYears();
}
else{
assetacct.setA_Period_End(asset.getUseLifeMonths());
uselifemonths = asset.getUseLifeMonths();
uselifeyears = asset.getUseLifeYears();}
// uselifemonths = asset.getUseLifeMonths();
// uselifeyears = asset.getUseLifeYears();
}
assetacct.setA_Depreciation_Method_ID(assetgrpacct.getA_Depreciation_Calc_Type());
assetacct.setA_Asset_Acct(assetgrpacct.getA_Asset_Acct());
@ -267,11 +278,12 @@ public class CreateGLAsset extends SvrProcess
sql2 ="SELECT * FROM A_Depreciation_Workfile WHERE A_Asset_ID = ? and PostingType = ?";
PreparedStatement pstmt2 = null;
pstmt2 = DB.prepareStatement(sql2,get_TrxName());
ResultSet rs3 = null;
log.info("no");
try {
pstmt2.setInt(1, asset.getA_Asset_ID());
pstmt2.setString(2, assetgrpacct.getPostingType());
ResultSet rs3 = pstmt2.executeQuery();
rs3 = pstmt2.executeQuery();
while (rs3.next()){
X_A_Depreciation_Workfile assetwk = new X_A_Depreciation_Workfile (getCtx(), rs3, get_TrxName());
assetwk.setA_Asset_ID(asset.getA_Asset_ID());
@ -311,26 +323,17 @@ public class CreateGLAsset extends SvrProcess
change.save();
}
rs3.close();
pstmt2.close();
pstmt2 = null;
}
catch (Exception e)
{
log.info("getAssets "+ e);
}
finally
{
try
{
if (pstmt2 != null)
pstmt2.close ();
}
catch (Exception e)
{}
pstmt2 = null;
}
finally
{
DB.close(rs3, pstmt2);
rs3 = null; pstmt2 = null;
}
}
}
}
@ -374,17 +377,10 @@ public class CreateGLAsset extends SvrProcess
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return "";
return "";
} // doIt
} // CreateGLAsset

View File

@ -13,16 +13,25 @@
*****************************************************************************/
package org.compiere.FA;
import java.sql.*;
import java.math.*;
import org.compiere.process.*;
import org.compiere.model.X_AD_Sequence;
import java.math.BigDecimal;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import org.compiere.model.MAccount;
import org.compiere.model.MJournal;
import org.compiere.model.MJournalBatch;
import org.compiere.model.MJournalLine;
import org.compiere.model.MAccount;
import org.compiere.model.*;
import org.compiere.util.*;
import org.compiere.model.MXIFAJournal;
import org.compiere.model.X_AD_Sequence;
import org.compiere.model.X_I_FAJournal;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.TimeUtil;
/**
@ -157,14 +166,14 @@ public class ImportFAJournal2 extends SvrProcess
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sqlst, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE,get_TrxName());
ResultSet rs = null;
try {
int v_FirstTime = 0;
String v_C_BatchNo = "";
BigDecimal v_AMTSOURCEDR ;
BigDecimal v_AMTSOURCECR ;
int v_ID_START = 10;
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
while (rs.next())
{
@ -237,24 +246,15 @@ public class ImportFAJournal2 extends SvrProcess
+ " WHERE A_DEPRECIATION_ENTRY_ID = " + rs.getInt("A_DEPRECIATION_ENTRY_ID"));
no = DB.executeUpdate (sql4,get_TrxName());
}
rs.close();
pstmt.close();
pstmt = null;
}catch (Exception e)
{
log.info("ImportFAJournal2"+ e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Set IsActive, Created/Updated
@ -674,7 +674,7 @@ public class ImportFAJournal2 extends SvrProcess
try
{
pstmt = DB.prepareStatement (sql.toString(),get_TrxName());
ResultSet rs = pstmt.executeQuery ();
rs = pstmt.executeQuery ();
if (rs.next ())
{
BigDecimal source = rs.getBigDecimal(1);
@ -689,23 +689,16 @@ public class ImportFAJournal2 extends SvrProcess
if (acct != null)
addLog (0, null, acct, "@AmtAcctDr@- @AmtAcctCr@");
}
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (SQLException ex)
{
log.info ("doIt - get balance"+ ex);
}
try
finally
{
if (pstmt != null)
pstmt.close ();
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
catch (SQLException ex1)
{
}
pstmt = null;
// Count Errors
int errors = DB.getSQLValue(get_TrxName(), "SELECT COUNT(*) FROM I_FAJournal WHERE I_IsImported NOT IN ('Y','N')" + clientCheck);
@ -740,7 +733,7 @@ public class ImportFAJournal2 extends SvrProcess
try
{
pstmt = DB.prepareStatement (sql.toString (),get_TrxName());
ResultSet rs = pstmt.executeQuery ();
rs = pstmt.executeQuery ();
//
while (rs.next())
{
@ -963,24 +956,17 @@ public class ImportFAJournal2 extends SvrProcess
noInsertLine++;
}
}
rs.close();
pstmt.close();
}
catch (Exception e)
{
log.info("doIt"+ e);
}
// clean up
try
{
if (pstmt != null)
pstmt.close ();
}
catch (SQLException ex1)
{
}
pstmt = null;
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Set Error to indicator to not imported
sql = new StringBuffer ("UPDATE I_FAJournal "
@ -1003,36 +989,25 @@ public class ImportFAJournal2 extends SvrProcess
+ "WHERE A_ASSET.A_ASSET_ID = A_DEPRECIATION_WORKFILE.A_ASSET_ID "
+ "AND A_DEPRECIATION_WORKFILE.A_PERIOD_POSTED = A_DEPRECIATION_WORKFILE.A_LIFE_PERIOD ";
pstmt = null;
try
{
pstmt = DB.prepareStatement(sql3,get_TrxName());
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
while (rs.next()){
String sql4 = "UPDATE A_ASSET SET ISFULLYDEPRECIATED = 'Y' WHERE A_Asset_ID = " + rs.getInt("A_ASSET_ID");
no = DB.executeUpdate (sql4,get_TrxName());
}
rs.close();
pstmt.close();
pstmt = null;
}
}
catch (Exception e)
{
log.info("Post Depreciation"+ e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return "";
} // doIt

View File

@ -16,11 +16,17 @@
*****************************************************************************/
package org.compiere.process;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.model.*;
import org.compiere.util.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.logging.Level;
import org.compiere.model.MBOM;
import org.compiere.model.MBOMProduct;
import org.compiere.model.MProduct;
import org.compiere.model.MProductBOM;
import org.compiere.util.DB;
import org.compiere.util.Env;
/**
* Validate BOM
@ -90,6 +96,7 @@ public class BOMValidate extends SvrProcess
sql += "AND IsVerified<>'Y' ";
sql += "ORDER BY Name";
int AD_Client_ID = Env.getAD_Client_ID(getCtx());
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql, null);
@ -97,30 +104,22 @@ public class BOMValidate extends SvrProcess
pstmt.setInt (1, AD_Client_ID);
else
pstmt.setInt(1, p_M_Product_Category_ID);
ResultSet rs = pstmt.executeQuery ();
rs = pstmt.executeQuery ();
while (rs.next ())
{
String info = validateProduct(new MProduct(getCtx(), p_M_Product_ID, get_TrxName()));
addLog(0, null, null, info);
counter++;
}
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
log.log (Level.SEVERE, sql, e);
}
try
finally
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return "#" + counter;
} // doIt