BF [ 1874419 ] JDBC Statement not close in a finally block - for ProductCost, Tax, Env, Msg

This commit is contained in:
teo_sarca 2008-02-04 23:50:24 +00:00
parent 432cfe0bc9
commit 3eff6ddfe5
4 changed files with 120 additions and 65 deletions

View File

@ -16,12 +16,16 @@
*****************************************************************************/
package org.compiere.model;
import java.math.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.*;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
/**
* Product Cost Model.
@ -158,21 +162,25 @@ public class ProductCost
+ "WHERE M_Product_ID=? AND C_AcctSchema_ID=?";
//
int validCombination_ID = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_M_Product_ID);
pstmt.setInt(2, as.getC_AcctSchema_ID());
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
if (rs.next())
validCombination_ID = rs.getInt(AcctType);
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
if (validCombination_ID == 0)
return null;
return MAccount.get(as.getCtx(), validCombination_ID);
@ -200,20 +208,24 @@ public class ProductCost
+ "ORDER BY pc.IsDefault DESC, pc.Created";
//
int validCombination_ID = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, as.getC_AcctSchema_ID());
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
if (rs.next())
validCombination_ID = rs.getInt(AcctType);
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
if (validCombination_ID == 0)
return null;
return MAccount.get(as.getCtx(), validCombination_ID);
@ -296,24 +308,28 @@ public class ProductCost
sql.append("COSTSTANDARD");
sql.append(" FROM M_Product_Costing WHERE M_Product_ID=? AND C_AcctSchema_ID=?");
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, m_M_Product_ID);
pstmt.setInt(2, as.getC_AcctSchema_ID());
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
if (rs.next())
{
current = rs.getBigDecimal(1);
cost = rs.getBigDecimal(2);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql.toString(), e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Return Costs
if (costType != null && cost != null && !cost.equals(Env.ZERO))
@ -415,11 +431,13 @@ public class ProductCost
BigDecimal PriceList = null;
BigDecimal PriceStd = null;
BigDecimal PriceLimit = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, m_M_Product_ID);
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
if (rs.next())
{
C_Currency_ID = rs.getInt(1);
@ -427,13 +445,15 @@ public class ProductCost
PriceStd = rs.getBigDecimal(3);
PriceLimit = rs.getBigDecimal(4);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql.toString(), e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// nothing found
if (C_Currency_ID == 0)
return null;
@ -466,11 +486,13 @@ public class ProductCost
BigDecimal PriceList = null;
BigDecimal PricePO = null;
BigDecimal PriceLastPO = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_M_Product_ID);
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
if (rs.next())
{
C_Currency_ID = rs.getInt(1);
@ -478,13 +500,15 @@ public class ProductCost
PricePO = rs.getBigDecimal(3);
PriceLastPO = rs.getBigDecimal(4);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// nothing found
if (C_Currency_ID == 0)
return null;

View File

@ -16,10 +16,18 @@
*****************************************************************************/
package org.compiere.model;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
/**
* Tax Handling
@ -111,7 +119,6 @@ public class Tax
log.warning("No Warehouse - C_Charge_ID=" + C_Charge_ID);
return 0;
}
String variable = "";
int C_TaxCategory_ID = 0;
int shipFromC_Location_ID = 0;
int shipToC_Location_ID = 0;
@ -130,15 +137,17 @@ public class Tax
+ " AND il.C_BPartner_Location_ID=?"
+ " AND w.M_Warehouse_ID=?"
+ " AND sl.C_BPartner_Location_ID=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
PreparedStatement pstmt = DB.prepareStatement (sql, null);
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, C_Charge_ID);
pstmt.setInt (2, AD_Org_ID);
pstmt.setInt (3, billC_BPartner_Location_ID);
pstmt.setInt (4, M_Warehouse_ID);
pstmt.setInt (5, shipC_BPartner_Location_ID);
ResultSet rs = pstmt.executeQuery ();
rs = pstmt.executeQuery ();
boolean found = false;
if (rs.next ())
{
@ -150,8 +159,7 @@ public class Tax
shipToC_Location_ID = rs.getInt (6);
found = true;
}
rs.close ();
pstmt.close ();
DB.close(rs, pstmt);
//
if (!found)
{
@ -169,6 +177,10 @@ public class Tax
log.log(Level.SEVERE, sql, e);
return 0;
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Reverese for PO
if (!IsSOTrx)
@ -230,6 +242,8 @@ public class Tax
int billToC_Location_ID = 0;
String IsTaxExempt = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
// Get all at once
@ -243,13 +257,13 @@ public class Tax
+ " AND il.C_BPartner_Location_ID=?"
+ " AND w.M_Warehouse_ID=?"
+ " AND sl.C_BPartner_Location_ID=?";
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, M_Product_ID);
pstmt.setInt(2, AD_Org_ID);
pstmt.setInt(3, billC_BPartner_Location_ID);
pstmt.setInt(4, M_Warehouse_ID);
pstmt.setInt(5, shipC_BPartner_Location_ID);
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
boolean found = false;
if (rs.next())
{
@ -261,8 +275,7 @@ public class Tax
shipToC_Location_ID = rs.getInt(6);
found = true;
}
rs.close();
pstmt.close();
DB.close(rs, pstmt);
//
if (found && "Y".equals(IsTaxExempt))
{
@ -307,8 +320,7 @@ public class Tax
C_TaxCategory_ID = rs.getInt(1);
found = true;
}
rs.close();
pstmt.close();
DB.close(rs, pstmt);
if (C_TaxCategory_ID == 0)
{
log.saveError("TaxCriteriaNotFound", Msg.translate(ctx, variable)
@ -330,8 +342,7 @@ public class Tax
billFromC_Location_ID = rs.getInt (1);
found = true;
}
rs.close();
pstmt.close();
DB.close(rs, pstmt);
if (billFromC_Location_ID == 0)
{
log.saveError("TaxCriteriaNotFound", Msg.translate(Env.getAD_Language(ctx), variable)
@ -354,8 +365,7 @@ public class Tax
IsTaxExempt = rs.getString(2);
found = true;
}
rs.close();
pstmt.close();
DB.close(rs, pstmt);
if (billToC_Location_ID == 0)
{
log.saveError("TaxCriteriaNotFound", Msg.translate(Env.getAD_Language(ctx), variable)
@ -390,8 +400,7 @@ public class Tax
shipFromC_Location_ID = rs.getInt (1);
found = true;
}
rs.close();
pstmt.close();
DB.close(rs, pstmt);
if (shipFromC_Location_ID == 0)
{
log.saveError("TaxCriteriaNotFound", Msg.translate(Env.getAD_Language(ctx), variable)
@ -412,8 +421,7 @@ public class Tax
shipToC_Location_ID = rs.getInt (1);
found = true;
}
rs.close();
pstmt.close();
DB.close(rs, pstmt);
if (shipToC_Location_ID == 0)
{
log.saveError("TaxCriteriaNotFound", Msg.translate(Env.getAD_Language(ctx), variable)
@ -435,6 +443,12 @@ public class Tax
{
log.log(Level.SEVERE, "getProduct (" + variable + ")", e);
}
finally
{
DB.close(rs);
DB.close(pstmt);
rs = null; pstmt = null;
}
return get (ctx, C_TaxCategory_ID, IsSOTrx,
shipDate, shipFromC_Location_ID, shipToC_Location_ID,
@ -456,23 +470,27 @@ public class Tax
+ "WHERE t.IsTaxExempt='Y' AND o.AD_Org_ID=? "
+ "ORDER BY t.Rate DESC";
boolean found = false;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Org_ID);
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
if (rs.next())
{
C_Tax_ID = rs.getInt (1);
found = true;
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, "getExemptTax", e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
log.fine("getExemptTax - TaxExempt=Y - C_Tax_ID=" + C_Tax_ID);
if (C_Tax_ID == 0)
log.saveError("TaxCriteriaNotFound", Msg.getMsg(ctx, "TaxNoExemptFound")

View File

@ -961,10 +961,12 @@ public final class Env
boolean isSystemLanguage = false;
ArrayList<String> AD_Languages = new ArrayList<String>();
String sql = "SELECT DISTINCT AD_Language FROM AD_Message_Trl";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
ResultSet rs = pstmt.executeQuery();
pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery();
while (rs.next())
{
String AD_Language = rs.getString(1);
@ -975,13 +977,15 @@ public final class Env
}
AD_Languages.add(AD_Language);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
s_log.log(Level.SEVERE, "", e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Found it
if (isSystemLanguage)
return;

View File

@ -108,9 +108,10 @@ public final class Msg
s_log.log(Level.SEVERE, "No DB Connection");
return null;
}
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
PreparedStatement pstmt = null;
if (AD_Language == null || AD_Language.length() == 0 || Env.isBaseLanguage(AD_Language, "AD_Language"))
pstmt = DB.prepareStatement("SELECT Value, MsgText, MsgTip FROM AD_Message", null);
else
@ -121,7 +122,7 @@ public final class Msg
+ " AND t.AD_Language=?", null);
pstmt.setString(1, AD_Language);
}
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
// get values
while (rs.next())
@ -135,14 +136,15 @@ public final class Msg
MsgText.append(" ").append(SEPARATOR).append(MsgTip);
msg.put(AD_Message, MsgText.toString());
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
s_log.log(Level.SEVERE, "initMsg", e);
return null;
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
//
if (msg.size() < 100)
@ -460,9 +462,10 @@ public final class Msg
// Check AD_Element
String retStr = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
PreparedStatement pstmt = null;
try
{
if (AD_Language == null || AD_Language.length() == 0 || Env.isBaseLanguage(AD_Language, "AD_Element"))
@ -479,8 +482,12 @@ public final class Msg
{
return ColumnName;
}
finally {
DB.close(rs);
rs = null;
}
pstmt.setString(1, ColumnName.toUpperCase());
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
if (rs.next())
{
retStr = rs.getString(1);
@ -491,13 +498,15 @@ public final class Msg
retStr = temp;
}
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
s_log.log(Level.SEVERE, "getElement", e);
return "";
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
if (retStr != null)
return retStr.trim();