package org.compiere.apps.search: fix db connection

This commit is contained in:
teo_sarca 2008-06-20 10:04:18 +00:00
parent 5126b0bf02
commit 3178d74907
5 changed files with 95 additions and 105 deletions

View File

@ -1038,9 +1038,11 @@ public final class Find extends CDialog
String retString = " M_Product_Category_ID IN (";
String sql = " SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category";
final Vector<SimpleTreeNode> categories = new Vector<SimpleTreeNode>(100);
Statement stmt = null;
ResultSet rs = null;
try {
Statement stmt = DB.createStatement();
ResultSet rs = stmt.executeQuery(sql);
stmt = DB.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
if(rs.getInt(1)==productCategoryId) {
subTreeRootParentId = rs.getInt(2);
@ -1049,8 +1051,6 @@ public final class Find extends CDialog
}
retString += getSubCategoriesString(productCategoryId, categories, subTreeRootParentId);
retString += ") ";
rs.close();
stmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
retString = "";
@ -1058,6 +1058,10 @@ public final class Find extends CDialog
log.log(Level.SEVERE, sql, e);
retString = "";
}
finally {
DB.close(rs, stmt);
rs = null; stmt = null;
}
return retString;
}
@ -1318,19 +1322,23 @@ public final class Find extends CDialog
// Execute Qusery
m_total = 999999;
Statement stmt = null;
ResultSet rs = null;
try
{
Statement stmt = DB.createStatement();
ResultSet rs = stmt.executeQuery(finalSQL);
stmt = DB.createStatement();
rs = stmt.executeQuery(finalSQL);
if (rs.next())
m_total = rs.getInt(1);
rs.close();
stmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, finalSQL, e);
}
finally {
DB.close(rs, stmt);
rs = null; stmt = null;
}
MRole role = MRole.getDefault();
// No Records
if (m_total == 0 && alertZeroRecords)

View File

@ -204,11 +204,13 @@ public class InfoGeneral extends Info
+ "ORDER BY c.IsIdentifier DESC, c.SeqNo";
int AD_Table_ID = 0;
String tableName = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql, null);
pstmt.setString(1, p_tableName);
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
while (rs.next())
{
m_queryColumns.add(rs.getString(1));
@ -232,6 +234,10 @@ public class InfoGeneral extends Info
log.log(Level.SEVERE, sql, e);
return false;
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Miminum check
if (m_queryColumns.size() == 0)
{
@ -267,9 +273,9 @@ public class InfoGeneral extends Info
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Table_ID);
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
while (rs.next())
{
String columnName = rs.getString(1);
@ -330,14 +336,16 @@ public class InfoGeneral extends Info
else
log.finest("Not Added Column=" + columnName);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
return false;
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
if (list.size() == 0)
{
ADialog.error(p_WindowNo, this, "Error", "No Info Columns");

View File

@ -134,6 +134,7 @@ public class InfoPAttribute extends CDialog
{
int row = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = MRole.getDefault().addAccessSQL(
"SELECT M_Attribute_ID, Name, Description, AttributeValueType, IsInstanceAttribute "
+ "FROM M_Attribute "
@ -143,7 +144,7 @@ public class InfoPAttribute extends CDialog
try
{
pstmt = DB.prepareStatement(sql, null);
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
boolean instanceLine = false;
while (rs.next())
{
@ -195,23 +196,14 @@ public class InfoPAttribute extends CDialog
else
m_productEditorsTo.add(fieldTo);
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return row;
} // addProductAttributes
@ -227,6 +219,7 @@ public class InfoPAttribute extends CDialog
list.add(new KeyNamePair(-1, ""));
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = MRole.getDefault().addAccessSQL(
"SELECT M_AttributeValue_ID, Value, Name "
+ "FROM M_AttributeValue "
@ -237,26 +230,17 @@ public class InfoPAttribute extends CDialog
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, M_Attribute_ID);
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
while (rs.next())
list.add(new KeyNamePair(rs.getInt(1), rs.getString(3)));
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
KeyNamePair[] retValue = new KeyNamePair[list.size()];
list.toArray(retValue);
@ -276,29 +260,21 @@ public class InfoPAttribute extends CDialog
"SELECT M_Lot_ID, Name FROM M_Lot WHERE IsActive='Y' ORDER BY 2",
"M_Lot", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
while (rs.next())
list.add(new KeyNamePair(rs.getInt(1), rs.getString(2)));
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Create List
KeyNamePair[] items = new KeyNamePair[list.size()];

View File

@ -196,20 +196,7 @@ public class InfoSchedule extends CDialog
if (m_mAssignment.getS_Resource_ID() != 0)
{
String sql = "SELECT S_ResourceType_ID FROM S_Resource WHERE S_Resource_ID=?";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_mAssignment.getS_Resource_ID());
ResultSet rs = pstmt.executeQuery();
if (rs.next())
S_ResourceType_ID = rs.getInt(1);
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
S_ResourceType_ID = DB.getSQLValue(null, sql, m_mAssignment.getS_Resource_ID());
}
// Get Resource Types
@ -217,10 +204,12 @@ public class InfoSchedule extends CDialog
"SELECT S_ResourceType_ID, Name FROM S_ResourceType WHERE IsActive='Y' ORDER BY 2",
"S_ResourceType", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
KeyNamePair defaultValue = null;
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())
{
KeyNamePair pp = new KeyNamePair(rs.getInt(1), rs.getString(2));
@ -228,13 +217,15 @@ public class InfoSchedule extends CDialog
defaultValue = pp;
fieldResourceType.addItem(pp);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
if (defaultValue != null)
fieldResourceType.setSelectedItem(defaultValue);
} // fillResourceType
@ -256,11 +247,13 @@ public class InfoSchedule extends CDialog
m_loading = true;
fieldResource.removeAllItems();
String sql = "SELECT S_Resource_ID, Name FROM S_Resource WHERE S_ResourceType_ID=? ORDER BY 2";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, S_ResourceType_ID);
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
while (rs.next())
{
pp = new KeyNamePair(rs.getInt(1), rs.getString(2));
@ -268,13 +261,15 @@ public class InfoSchedule extends CDialog
defaultValue = pp;
fieldResource.addItem(pp);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
if (defaultValue != null)
fieldResource.setSelectedItem(defaultValue);

View File

@ -236,11 +236,13 @@ public class InvoiceHistory extends CDialog
{
log.fine(sql + "; Parameter=" + parameter);
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, parameter);
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
while (rs.next())
{
Vector<Object> line = new Vector<Object>(6);
@ -264,13 +266,15 @@ public class InvoiceHistory extends CDialog
line.add(rs.getString(7)); // Org/Warehouse
data.add(line);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
log.fine("#" + data.size());
return data;
} // fillTable
@ -282,20 +286,9 @@ public class InvoiceHistory extends CDialog
private void fillLabel (String sql, int parameter)
{
log.fine(sql + "; Parameter=" + parameter);
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, parameter);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
label.setText(rs.getString(1));
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
String retValue = DB.getSQLValueString(null, sql, parameter);
if (retValue != null)
label.setText(retValue);
} // fillLabel
@ -467,11 +460,13 @@ public class InvoiceHistory extends CDialog
parameter = m_C_BPartner_ID;
}
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, parameter);
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
while (rs.next())
{
Vector<Object> line = new Vector<Object>(6);
@ -484,13 +479,15 @@ public class InvoiceHistory extends CDialog
line.add(rs.getString(6)); // Warehouse
data.add(line);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
log.fine("#" + data.size());
// Table
@ -551,15 +548,17 @@ public class InvoiceHistory extends CDialog
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
double qty = 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);
if (m_M_Warehouse_ID != 0)
pstmt.setInt(2, m_M_Warehouse_ID);
if (m_M_AttributeSetInstance_ID > 0)
pstmt.setInt(3, m_M_AttributeSetInstance_ID);
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
while (rs.next())
{
Vector<Object> line = new Vector<Object>(9);
@ -579,13 +578,15 @@ public class InvoiceHistory extends CDialog
line.add(rs.getString(6)); // Warehouse
data.add(line);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Orders
sql = "SELECT o.DatePromised, ol.QtyReserved,"
@ -606,13 +607,13 @@ public class InvoiceHistory extends CDialog
sql += " ORDER BY o.DatePromised";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_M_Product_ID);
if (m_M_Warehouse_ID != 0)
pstmt.setInt(2, m_M_Warehouse_ID);
if (m_M_AttributeSetInstance_ID > 0)
pstmt.setInt(3, m_M_AttributeSetInstance_ID);
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
while (rs.next())
{
Vector<Object> line = new Vector<Object>(9);
@ -644,13 +645,15 @@ public class InvoiceHistory extends CDialog
line.add(rs.getString(8)); // Warehouse
data.add(line);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Table
MiniTable table = null;