From 7838f1bf048f9912b580f078260056f98409accf Mon Sep 17 00:00:00 2001 From: Richard Morales Date: Fri, 15 Feb 2013 19:26:22 -0500 Subject: [PATCH] IDEMPIERE-568 Review proper closing of JDBC statements and resultsets --- .../src/org/adempiere/process/Export.java | 10 +-- .../src/org/compiere/acct/Doc.java | 28 +++++--- .../src/org/compiere/acct/Doc_Production.java | 58 ++++++++------- .../src/org/compiere/db/CreateAdempiere.java | 15 ++-- .../src/compiere/model/CalloutUser.java | 44 ++++++++---- .../src/org/compiere/acct/AcctViewerData.java | 42 +++++++---- .../src/org/compiere/apps/AEnv.java | 28 +++++--- .../src/org/compiere/apps/APanel.java | 14 ++-- .../org/compiere/apps/ProcessParameter.java | 14 ++-- .../src/org/compiere/apps/RecordInfo.java | 16 ++--- .../org/compiere/apps/form/VFileImport.java | 14 ++-- .../org/compiere/apps/search/InfoGeneral.java | 2 - .../org/compiere/grid/RecordAccessDialog.java | 16 ++--- .../src/org/compiere/grid/ed/Calculator.java | 14 ++-- .../src/org/compiere/grid/ed/VAccount.java | 16 ++--- .../org/compiere/grid/ed/VAccountDialog.java | 29 +++++--- .../src/org/compiere/grid/ed/VAssignment.java | 9 ++- .../compiere/grid/ed/VAssignmentDialog.java | 14 ++-- .../src/org/compiere/grid/ed/VButton.java | 15 ++-- .../src/org/compiere/grid/ed/VColor.java | 14 ++-- .../src/org/compiere/grid/ed/VLocator.java | 18 ++--- .../org/compiere/grid/ed/VLocatorDialog.java | 14 ++-- .../adempiere/webui/acct/WAcctViewerData.java | 49 ++++++++----- .../src/org/adempiere/webui/apps/AEnv.java | 29 +++++--- .../webui/apps/ProcessParameterPanel.java | 13 ++-- .../webui/apps/form/WAttributeGrid.java | 35 +++++---- .../webui/apps/form/WFileImport.java | 15 ++-- .../webui/editor/WAccountEditor.java | 3 - .../webui/editor/WAssignmentEditor.java | 8 ++- .../webui/editor/WLocatorEditor.java | 20 ++---- .../adempiere/webui/editor/WSearchEditor.java | 20 ++---- .../webui/panel/InfoGeneralPanel.java | 26 ++++--- .../org/adempiere/webui/panel/InfoPanel.java | 31 ++++---- .../adempiere/webui/window/FindWindow.java | 27 ++++--- .../adempiere/webui/window/InfoSchedule.java | 42 +++++++---- .../webui/window/WAccountDialog.java | 28 +++++--- .../webui/window/WAssignmentDialog.java | 14 ++-- .../webui/window/WLocatorDialog.java | 32 +++++---- .../webui/window/WRecordAccessDialog.java | 18 ++--- .../adempiere/webui/window/WRecordInfo.java | 16 ++--- .../webui/window/ZkReportViewer.java | 44 ++++++++---- .../src/org/compiere/apps/form/Charge.java | 43 +++++++---- .../org/compiere/apps/form/FactReconcile.java | 28 +++++--- .../src/org/compiere/apps/form/InOutGen.java | 14 ++-- .../org/compiere/apps/form/InvoiceGen.java | 14 ++-- .../src/org/compiere/apps/form/Merge.java | 23 +++--- .../src/org/compiere/apps/form/PayPrint.java | 68 ++++++++++++------ .../src/org/compiere/apps/form/PaySelect.java | 71 +++++++++++++------ .../org/compiere/apps/form/TrxMaterial.java | 14 ++-- .../grid/CreateFromPackageShipment.java | 14 ++-- .../src/org/compiere/grid/CreateFromRMA.java | 14 ++-- .../src/org/compiere/grid/PaymentForm.java | 29 +++++--- .../org/compiere/grid/PaymentFormCash.java | 28 +++++--- .../org/compiere/grid/PaymentFormCheck.java | 14 ++-- .../org/compiere/grid/PaymentFormDirect.java | 14 ++-- .../compiere/grid/PaymentFormOnCredit.java | 14 ++-- .../src/net/sf/compilo/report/ReportInfo.java | 11 +-- 57 files changed, 835 insertions(+), 492 deletions(-) diff --git a/org.adempiere.base.process/src/org/adempiere/process/Export.java b/org.adempiere.base.process/src/org/adempiere/process/Export.java index 4695cf27de..52d08d76bc 100644 --- a/org.adempiere.base.process/src/org/adempiere/process/Export.java +++ b/org.adempiere.base.process/src/org/adempiere/process/Export.java @@ -182,10 +182,7 @@ public class Export extends SvrProcess } } finally { - try { - if (rs != null) rs.close(); - if (pstmt != null) pstmt.close(); - } catch (SQLException ex) {/*ignored*/} + DB.close(rs, pstmt); rs = null; pstmt = null; } @@ -378,10 +375,7 @@ public class Export extends SvrProcess } } finally { - try { - if (rsEmbedded != null) rsEmbedded.close(); - if (pstmt != null) pstmt.close(); - } catch (SQLException ex) { } + DB.close(rsEmbedded, pstmt); rsEmbedded = null; pstmt = null; } diff --git a/org.adempiere.base/src/org/compiere/acct/Doc.java b/org.adempiere.base/src/org/compiere/acct/Doc.java index 3c741700f2..0b4e9fd6f3 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc.java @@ -845,21 +845,27 @@ public abstract class Doc { String sql = "SELECT GL_Category_ID FROM C_DocType " + "WHERE AD_Client_ID=? AND DocBaseType=?"; + PreparedStatement pstmt = null; + ResultSet rsDT = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), null); pstmt.setInt(1, getAD_Client_ID()); pstmt.setString(2, m_DocumentType); - ResultSet rsDT = pstmt.executeQuery(); + rsDT = pstmt.executeQuery(); if (rsDT.next()) m_GL_Category_ID = rsDT.getInt(1); - rsDT.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rsDT, pstmt); + rsDT = null; + pstmt = null; + } } // Still no GL_Category - get Default GL Category @@ -868,20 +874,26 @@ public abstract class Doc String sql = "SELECT GL_Category_ID FROM GL_Category " + "WHERE AD_Client_ID=? " + "ORDER BY IsDefault DESC"; + PreparedStatement pstmt = null; + ResultSet rsDT = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, getAD_Client_ID()); - ResultSet rsDT = pstmt.executeQuery(); + rsDT = pstmt.executeQuery(); if (rsDT.next()) m_GL_Category_ID = rsDT.getInt(1); - rsDT.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rsDT, pstmt); + rsDT = null; + pstmt = null; + } } // if (m_GL_Category_ID == 0) diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_Production.java b/org.adempiere.base/src/org/compiere/acct/Doc_Production.java index 0579f2e251..8931f8ef0a 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_Production.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_Production.java @@ -83,36 +83,40 @@ public class Doc_Production extends Doc String sqlPL = "SELECT * FROM M_ProductionLine pl " + "WHERE pl.M_Production_ID=? " + "ORDER BY pl.Line"; - + PreparedStatement pstmtPL = null; + ResultSet rsPL = null; try - { - - PreparedStatement pstmtPL = DB.prepareStatement(sqlPL, getTrxName()); - pstmtPL.setInt(1,get_ID()); - ResultSet rsPL = pstmtPL.executeQuery(); - while (rsPL.next()) - { - X_M_ProductionLine line = new X_M_ProductionLine(getCtx(), rsPL, getTrxName()); - if (line.getMovementQty().signum() == 0) - { - log.info("LineQty=0 - " + line); - continue; - } - DocLine docLine = new DocLine (line, this); - docLine.setQty (line.getMovementQty(), false); - // Identify finished BOM Product - docLine.setProductionBOM(line.getM_Product_ID() == prod.getM_Product_ID()); - // - log.fine(docLine.toString()); - list.add (docLine); - } - rsPL.close(); - pstmtPL.close(); - } - catch (Exception ee) + { + pstmtPL = DB.prepareStatement(sqlPL, getTrxName()); + pstmtPL.setInt(1,get_ID()); + rsPL = pstmtPL.executeQuery(); + while (rsPL.next()) + { + X_M_ProductionLine line = new X_M_ProductionLine(getCtx(), rsPL, getTrxName()); + if (line.getMovementQty().signum() == 0) { - log.log(Level.SEVERE, sqlPL, ee); + log.info("LineQty=0 - " + line); + continue; } + DocLine docLine = new DocLine (line, this); + docLine.setQty (line.getMovementQty(), false); + // Identify finished BOM Product + docLine.setProductionBOM(line.getM_Product_ID() == prod.getM_Product_ID()); + // + log.fine(docLine.toString()); + list.add (docLine); + } + } + catch (Exception ee) + { + log.log(Level.SEVERE, sqlPL, ee); + } + finally + { + DB.close(rsPL, pstmtPL); + rsPL = null; + pstmtPL = null; + } DocLine[] dl = new DocLine[list.size()]; list.toArray(dl); diff --git a/org.adempiere.base/src/org/compiere/db/CreateAdempiere.java b/org.adempiere.base/src/org/compiere/db/CreateAdempiere.java index 0eb2d6164c..8e2d1564c3 100644 --- a/org.adempiere.base/src/org/compiere/db/CreateAdempiere.java +++ b/org.adempiere.base/src/org/compiere/db/CreateAdempiere.java @@ -353,11 +353,13 @@ public class CreateAdempiere StringBuilder sb = new StringBuilder("CREATE TABLE "); sb.append(tableName).append(" ("); + ResultSet sourceColumns = null; + ResultSet sourcePK = null; try { // Columns boolean first = true; - ResultSet sourceColumns = md.getColumns(catalog, schema, table, null); + sourceColumns = md.getColumns(catalog, schema, table, null); while (sourceColumns.next()) { sb.append(first ? "" : ", "); @@ -431,10 +433,9 @@ public class CreateAdempiere } // for all columns - sourceColumns.close(); // Primary Key - ResultSet sourcePK = md.getPrimaryKeys(catalog, schema, table); + sourcePK = md.getPrimaryKeys(catalog, schema, table); // TABLE_CAT=null, TABLE_SCHEM=REFERENCE, TABLE_NAME=A_ASSET, COLUMN_NAME=A_ASSET_ID, KEY_SEQ=1, PK_NAME=A_ASSET_KEY first = true; boolean hasPK = false; @@ -451,7 +452,6 @@ public class CreateAdempiere } if (hasPK) // close constraint sb.append(")"); // USING INDEX TABLESPACE INDX - sourcePK.close(); // sb.append(")"); // close create table } @@ -460,6 +460,13 @@ public class CreateAdempiere log.log(Level.SEVERE, "createTable", ex); return false; } + finally + { + DB.close(sourceColumns); + DB.close(sourcePK); + sourceColumns = null; + sourcePK = null; + } // Execute Create Table if (!executeCommands(new String[]{sb.toString()}, m_conn, false, true)) diff --git a/org.adempiere.extend/src/compiere/model/CalloutUser.java b/org.adempiere.extend/src/compiere/model/CalloutUser.java index 5c541082bf..1469b04c7f 100644 --- a/org.adempiere.extend/src/compiere/model/CalloutUser.java +++ b/org.adempiere.extend/src/compiere/model/CalloutUser.java @@ -89,11 +89,13 @@ public class CalloutUser extends CalloutEngine + " LEFT OUTER JOIN AD_User c ON (p.C_BPartner_ID=c.C_BPartner_ID) " + "WHERE p.C_BPartner_ID=? AND p.IsActive='Y'"; // #1 + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, C_BPartner_ID.intValue()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); // if (rs.next()) { @@ -125,14 +127,18 @@ public class CalloutUser extends CalloutEngine else mTab.setValue("AD_User_ID", new Integer(contID)); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); return e.getLocalizedMessage(); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return ""; } // bPartner @@ -160,20 +166,26 @@ public class CalloutUser extends CalloutEngine // String retValue = value; String SQL = "SELECT FRIE_Name(?) FROM DUAL"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(SQL, null); + pstmt = DB.prepareStatement(SQL, null); pstmt.setString(1, value); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) - retValue = rs.getString(1); - rs.close(); - pstmt.close(); + retValue = rs.getString(1); } catch (SQLException e) { log.log(Level.SEVERE, SQL, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return retValue; } // Frie_Name @@ -191,20 +203,26 @@ public class CalloutUser extends CalloutEngine // String retValue = value; String SQL = "SELECT FRIE_Value(FRIE_Name(?)) FROM DUAL"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(SQL, null); + pstmt = DB.prepareStatement(SQL, null); pstmt.setString(1, value); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) retValue = rs.getString(1); - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, SQL, e); } + finally + { + DB.close(rs,pstmt); + rs = null; + pstmt = null; + } return retValue; } // Frie_Value diff --git a/org.adempiere.ui.swing/src/org/compiere/acct/AcctViewerData.java b/org.adempiere.ui.swing/src/org/compiere/acct/AcctViewerData.java index 8733f16ca4..1e475a5982 100644 --- a/org.adempiere.ui.swing/src/org/compiere/acct/AcctViewerData.java +++ b/org.adempiere.ui.swing/src/org/compiere/acct/AcctViewerData.java @@ -195,10 +195,12 @@ class AcctViewerData + "WHERE EXISTS (SELECT * FROM AD_Column c" + " WHERE t.AD_Table_ID=c.AD_Table_ID AND c.ColumnName='Posted')" + " AND IsView='N'"; + 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()) { int id = rs.getInt(1); @@ -211,13 +213,17 @@ class AcctViewerData if (id == AD_Table_ID) select = pp; } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } if (select != null) cb.setSelectedItem(select); } // fillTable @@ -232,20 +238,26 @@ class AcctViewerData KeyNamePair pp = new KeyNamePair(0, ""); cb.addItem(pp); String sql = "SELECT AD_Org_ID, Name FROM AD_Org WHERE AD_Client_ID=? ORDER BY Value"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, AD_Client_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) cb.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2))); - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs,pstmt); + rs = null; + pstmt = null; + } } // fillOrg /** @@ -264,19 +276,25 @@ class AcctViewerData sql.append(MLookupFactory.getLookup_TableDirEmbed(language, columnName, "avd")) .append(") FROM ").append(tableName).append(" avd WHERE avd.").append(selectSQL); String retValue = "<" + selectSQL + ">"; + Statement stmt = null; + ResultSet rs = null; try { - Statement stmt = DB.createStatement(); - ResultSet rs = stmt.executeQuery(sql.toString()); + stmt = DB.createStatement(); + rs = stmt.executeQuery(sql.toString()); if (rs.next()) retValue = rs.getString(1); - rs.close(); - stmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); } + finally + { + DB.close(rs, stmt); + rs = null; + stmt = null; + } return retValue; } // getButtonText diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/AEnv.java b/org.adempiere.ui.swing/src/org/compiere/apps/AEnv.java index dcc9469862..243d0cb576 100644 --- a/org.adempiere.ui.swing/src/org/compiere/apps/AEnv.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/AEnv.java @@ -635,24 +635,30 @@ public final class AEnv int AD_Window_ID = 0; int PO_Window_ID = 0; String sql = "SELECT TableName, AD_Window_ID, PO_Window_ID FROM AD_Table WHERE AD_Table_ID=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; 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(); if (rs.next()) { TableName = rs.getString(1); AD_Window_ID = rs.getInt(2); PO_Window_ID = rs.getInt(3); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // Nothing to Zoom to if (TableName == null || AD_Window_ID == 0) return; @@ -695,23 +701,29 @@ public final class AEnv int AD_Window_ID = 0; int PO_Window_ID = 0; String sql = "SELECT AD_Window_ID, PO_Window_ID FROM AD_Table WHERE TableName=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setString(1, TableName); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { AD_Window_ID = rs.getInt(1); PO_Window_ID = rs.getInt(2); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // Nothing to Zoom to if (AD_Window_ID == 0) return; diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/APanel.java b/org.adempiere.ui.swing/src/org/compiere/apps/APanel.java index fcb829bf5e..caddc1bbdc 100644 --- a/org.adempiere.ui.swing/src/org/compiere/apps/APanel.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/APanel.java @@ -2209,21 +2209,25 @@ public final class APanel extends CPanel + Env.getAD_Language(Env.getCtx()) + "'" + " AND l.AD_Reference_ID=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB - .prepareStatement(SQL, null); + pstmt = DB.prepareStatement(SQL, null); pstmt.setInt(1, AD_Reference_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { String value = rs.getString(1); String name = rs.getString(2); values.put(value, name); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, SQL, e); } + finally{ + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // Nothing to show or Record_ID if (field.getValue() == null diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/ProcessParameter.java b/org.adempiere.ui.swing/src/org/compiere/apps/ProcessParameter.java index b8bf553f2d..e3391def1e 100644 --- a/org.adempiere.ui.swing/src/org/compiere/apps/ProcessParameter.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/ProcessParameter.java @@ -233,23 +233,29 @@ public class ProcessParameter extends CDialog // Create Fields boolean hasFields = false; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_processInfo.getAD_Process_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { hasFields = true; createField (rs); } - rs.close(); - pstmt.close(); } catch(SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // both vectors the same? if (m_mFields.size() != m_mFields2.size() diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/RecordInfo.java b/org.adempiere.ui.swing/src/org/compiere/apps/RecordInfo.java index de155c4d2a..e40ac8ba03 100644 --- a/org.adempiere.ui.swing/src/org/compiere/apps/RecordInfo.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/RecordInfo.java @@ -209,33 +209,27 @@ public class RecordInfo extends CDialog + "WHERE AD_Table_ID=? AND Record_ID=? " + "ORDER BY Updated DESC"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, dse.AD_Table_ID); pstmt.setInt (2, Record_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { addLine (rs.getInt(1), rs.getTimestamp(2), rs.getInt(3), rs.getString(4), rs.getString(5)); } - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/form/VFileImport.java b/org.adempiere.ui.swing/src/org/compiere/apps/form/VFileImport.java index 4cb7f36f94..231dd386f9 100644 --- a/org.adempiere.ui.swing/src/org/compiere/apps/form/VFileImport.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/form/VFileImport.java @@ -208,19 +208,25 @@ public class VFileImport extends CPanel pickFormat.addItem(s_none); String sql = MRole.getDefault().addAccessSQL("SELECT Name FROM AD_ImpFormat", "AD_ImpFormat", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO); + 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()) pickFormat.addItem(rs.getString(1)); - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } pickFormat.setSelectedIndex(0); pickFormat.addActionListener(this); // diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/search/InfoGeneral.java b/org.adempiere.ui.swing/src/org/compiere/apps/search/InfoGeneral.java index a84e47886f..759c67d5e1 100644 --- a/org.adempiere.ui.swing/src/org/compiere/apps/search/InfoGeneral.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/search/InfoGeneral.java @@ -265,8 +265,6 @@ public class InfoGeneral extends Info tableName = rs.getString(3); } } - rs.close(); - pstmt.close(); } catch (SQLException e) { diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/RecordAccessDialog.java b/org.adempiere.ui.swing/src/org/compiere/grid/RecordAccessDialog.java index f26932a678..33e8e3d752 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/RecordAccessDialog.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/RecordAccessDialog.java @@ -123,31 +123,25 @@ public class RecordAccessDialog extends CDialog sql = "SELECT * FROM AD_Record_Access " + "WHERE AD_Table_ID=? AND Record_ID=? AND AD_Client_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_AD_Table_ID); pstmt.setInt(2, m_Record_ID); pstmt.setInt(3, Env.getAD_Client_ID(Env.getCtx())); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) m_recordAccesss.add(new MRecordAccess(Env.getCtx(), rs, null)); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } log.fine("#" + m_recordAccesss.size()); diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/ed/Calculator.java b/org.adempiere.ui.swing/src/org/compiere/grid/ed/Calculator.java index 8b10008888..8b8efece30 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/Calculator.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/Calculator.java @@ -576,10 +576,12 @@ public final class Calculator extends CDialog String sql = "SELECT C_Currency_ID, ISO_Code FROM C_Currency " + "WHERE IsActive='Y' ORDER BY 2"; KeyNamePair defaultValue = null; + 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()) { int id = rs.getInt("C_Currency_ID"); @@ -591,13 +593,17 @@ public final class Calculator extends CDialog if (id == C_Currency_ID) defaultValue = p; } - rs.close(); - stmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, "Calculator.loadCurrency", e); } + finally + { + DB.close(rs, stmt); + rs = null; + stmt = null; + } // Set Defaults if (defaultValue != null) diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAccount.java b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAccount.java index 53974a9c9d..51cbe4d7fa 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAccount.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAccount.java @@ -373,35 +373,29 @@ public final class VAccount extends JComponent // int C_ValidCombination_ID = 0; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, C_AcctSchema_ID); pstmt.setString(2, text.toUpperCase()); pstmt.setString(3, text.toUpperCase()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { C_ValidCombination_ID = rs.getInt(1); if (rs.next()) // only one C_ValidCombination_ID = 0; } - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // We have a Value diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAccountDialog.java b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAccountDialog.java index 199af65e93..83b97b8eb4 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAccountDialog.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAccountDialog.java @@ -519,12 +519,14 @@ public final class VAccountDialog extends CDialog { log.fine("C_ValidCombination_ID=" + C_ValidCombination_ID); String sql = "SELECT * FROM C_ValidCombination WHERE C_ValidCombination_ID=? AND C_AcctSchema_ID=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, C_ValidCombination_ID); pstmt.setInt(2, C_AcctSchema_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { if (f_Alias != null) @@ -549,13 +551,17 @@ public final class VAccountDialog extends CDialog // f_Description.setText (rs.getString("Description")); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } } // loadInfo /** @@ -920,25 +926,32 @@ public final class VAccountDialog extends CDialog log.fine("Check = " + sql.toString()); int IDvalue = 0; String Alias = 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_AD_Client_ID); pstmt.setInt(2, s_AcctSchema.getC_AcctSchema_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { IDvalue = rs.getInt(1); Alias = rs.getString(2); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); IDvalue = 0; } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } + log.fine("ID=" + IDvalue + ", Alias=" + Alias); if (Alias == null) diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAssignment.java b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAssignment.java index 0ed09e4a0a..5a03c6ba58 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAssignment.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAssignment.java @@ -309,10 +309,11 @@ public class VAssignment extends JComponent + " AND r.S_ResourceType_ID=rt.S_ResourceType_ID" + " and rt.C_UOM_ID=uom.C_UOM_ID", null); // + ResultSet rs = null; try { m_pstmt.setInt(1, S_ResourceAssignment_ID); - ResultSet rs = m_pstmt.executeQuery(); + rs = m_pstmt.executeQuery(); if (rs.next()) { StringBuilder sb = new StringBuilder(rs.getString(1)); @@ -323,12 +324,16 @@ public class VAssignment extends JComponent } else m_text.setText("<" + S_ResourceAssignment_ID + ">"); - rs.close(); } catch (Exception e) { log.log(Level.SEVERE, "", e); } + finally + { + DB.close(rs); + rs = null; + } } // setValue /** diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAssignmentDialog.java b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAssignmentDialog.java index a334775dc1..6f249d7607 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAssignmentDialog.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAssignmentDialog.java @@ -348,10 +348,12 @@ public class VAssignmentDialog extends CDialog + "FROM S_Resource r, S_ResourceType rt, C_UOM uom " + "WHERE r.S_ResourceType_ID=rt.S_ResourceType_ID AND rt.C_UOM_ID=uom.C_UOM_ID", "r", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO); + 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()) { StringBuilder sb = new StringBuilder (rs.getString(2)); @@ -363,13 +365,17 @@ public class VAssignmentDialog extends CDialog KeyNamePair value = new KeyNamePair (rs.getInt(4), rs.getString(5).trim()); m_lookup.put(key, value); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } } // Convert to Array KeyNamePair[] retValue = new KeyNamePair[m_lookup.size()]; diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VButton.java b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VButton.java index 3a12df4577..174f8deb28 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VButton.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VButton.java @@ -312,25 +312,30 @@ public final class VButton extends CButton + "WHERE l.AD_Ref_List_ID=t.AD_Ref_List_ID" + " AND t.AD_Language='" + Env.getAD_Language(Env.getCtx()) + "'" + " AND l.AD_Reference_ID=?"; - + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(SQL, null); + pstmt = DB.prepareStatement(SQL, null); pstmt.setInt(1, AD_Reference_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { String value = rs.getString(1); String name = rs.getString(2); m_values.put(value, name); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, SQL, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } } // readReference /** diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VColor.java b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VColor.java index b17eee14bf..bc717c3fc8 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VColor.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VColor.java @@ -272,22 +272,28 @@ public class VColor extends CButton // String retValue = null; String sql = "SELECT ImageURL FROM AD_Image WHERE AD_Image_ID=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt (1, AD_Image_ID.intValue()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { retValue = rs.getString(1); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return retValue; } // getURL diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocator.java b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocator.java index a605419dff..53e3c93937 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocator.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocator.java @@ -463,6 +463,7 @@ public class VLocator extends JComponent // int M_Locator_ID = 0; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(finalSql, null); @@ -474,30 +475,25 @@ public class VLocator extends JComponent pstmt.setInt(index++, only_Product_ID); pstmt.setInt(index++, only_Product_ID); } - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { M_Locator_ID = rs.getInt(1); if (rs.next()) M_Locator_ID = 0; // more than one } - rs.close(); - pstmt.close(); - pstmt = null; } catch (SQLException ex) { log.log(Level.SEVERE, finalSql, ex); } - try + finally { - if (pstmt != null) - pstmt.close(); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } - catch (SQLException ex1) - { - } - pstmt = null; + if (M_Locator_ID == 0) return false; diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocatorDialog.java b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocatorDialog.java index 736c3cd8fb..866fec07df 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocatorDialog.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocatorDialog.java @@ -385,11 +385,13 @@ public class VLocatorDialog extends CDialog // String SQL = "SELECT M_Warehouse_ID, Value, Name, Separator, AD_Client_ID, AD_Org_ID " + "FROM M_Warehouse WHERE M_Warehouse_ID=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(SQL, null); + pstmt = DB.prepareStatement(SQL, null); pstmt.setInt(1, M_Warehouse_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { m_M_Warehouse_ID = rs.getInt(1); @@ -399,13 +401,17 @@ public class VLocatorDialog extends CDialog m_AD_Client_ID = rs.getInt(5); m_AD_Org_ID = rs.getInt(6); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, SQL, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } } // getWarehouseInfo /** diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewerData.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewerData.java index a16c217966..efead00ca6 100755 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewerData.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewerData.java @@ -226,11 +226,12 @@ public class WAcctViewerData + "WHERE EXISTS (SELECT * FROM AD_Column c" + " WHERE t.AD_Table_ID=c.AD_Table_ID AND c.ColumnName='Posted')" + " AND IsView='N'"; - + 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()) { @@ -245,13 +246,17 @@ public class WAcctViewerData if (id == AD_Table_ID) select = pp; } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } if (select != null) ;//cb.setSelectedItem(select); @@ -268,26 +273,30 @@ public class WAcctViewerData KeyNamePair pp = new KeyNamePair(0, ""); cb.appendItem(pp.getName(), pp); String sql = "SELECT AD_Org_ID, Name FROM AD_Org WHERE AD_Client_ID=? ORDER BY Value"; - + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, AD_Client_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { KeyNamePair key = new KeyNamePair(rs.getInt(1), rs.getString(2)); cb.appendItem(key.getName(), key); } - - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } } // fillOrg /** @@ -309,21 +318,27 @@ public class WAcctViewerData sql.append(MLookupFactory.getLookup_TableDirEmbed(language, columnName, "avd")) .append(") FROM ").append(tableName).append(" avd WHERE avd.").append(selectSQL); String retValue = "<" + selectSQL + ">"; - + + Statement stmt = null; + ResultSet rs = null; try { - Statement stmt = DB.createStatement(); - ResultSet rs = stmt.executeQuery(sql.toString()); - + stmt = DB.createStatement(); + rs = stmt.executeQuery(sql.toString()); + if (rs.next()) retValue = rs.getString(1); - rs.close(); - stmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); } + finally + { + DB.close(rs, stmt); + rs = null; + stmt = null; + } return retValue; } // getButtonText diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java index 4cc2770b49..ed26e11277 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java @@ -156,24 +156,31 @@ public final class AEnv int AD_Window_ID = 0; int PO_Window_ID = 0; String sql = "SELECT TableName, AD_Window_ID, PO_Window_ID FROM AD_Table WHERE AD_Table_ID=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; 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(); if (rs.next()) { TableName = rs.getString(1); AD_Window_ID = rs.getInt(2); PO_Window_ID = rs.getInt(3); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // Nothing to Zoom to if (TableName == null || AD_Window_ID == 0) return; @@ -496,23 +503,29 @@ public final class AEnv int AD_Window_ID = 0; int PO_Window_ID = 0; String sql = "SELECT AD_Window_ID, PO_Window_ID FROM AD_Table WHERE TableName=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setString(1, TableName); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { AD_Window_ID = rs.getInt(1); PO_Window_ID = rs.getInt(2); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // Nothing to Zoom to if (AD_Window_ID == 0) return; diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java index a02b21ef00..0e0f17f69c 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java @@ -222,19 +222,24 @@ public class ProcessParameterPanel extends Panel implements // Create Fields boolean hasFields = false; Rows rows = new Rows(); + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_processInfo.getAD_Process_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { hasFields = true; createField(rs, rows); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally{ + DB.close(rs,pstmt); + rs = null; + pstmt = null; + } // both vectors the same? if (m_mFields.size() != m_mFields2.size() diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WAttributeGrid.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WAttributeGrid.java index aa3ab619f3..3e7aabed36 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WAttributeGrid.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WAttributeGrid.java @@ -266,18 +266,20 @@ public class WAttributeGrid extends ADForm implements EventListener // Add Access & Order sql = MRole.getDefault().addAccessSQL (sql, "M_PriceList_Version", true, false) // fully qualidfied - RO + " ORDER BY M_PriceList_Version.Name"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { pickPriceList.appendItem("", 0); - PreparedStatement pstmt = DB.prepareStatement(sql, null); - ResultSet rs = pstmt.executeQuery(); + pstmt = DB.prepareStatement(sql, null); + rs = pstmt.executeQuery(); while (rs.next()) { KeyNamePair kn = new KeyNamePair (rs.getInt(1), rs.getString(2)); pickPriceList.appendItem(kn.getName(), kn.getKey()); } - rs.close(); - pstmt.close(); + DB.close(rs, pstmt); + rs = null; pstmt = null; // Warehouse sql = "SELECT M_Warehouse_ID, Value || ' - ' || Name AS ValueName " @@ -295,13 +297,16 @@ public class WAttributeGrid extends ADForm implements EventListener (rs.getInt("M_Warehouse_ID"), rs.getString("ValueName")); pickWarehouse.appendItem(kn.getName(), kn.getKey()); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; pstmt = null; + } } // fillPicks public void onEvent(Event e) throws Exception @@ -522,36 +527,30 @@ public class WAttributeGrid extends ADForm implements EventListener sql = MRole.getDefault().addAccessSQL(sql, "M_Product", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO); PreparedStatement pstmt = null; + ResultSet rs = null ; int noProducts = 0; try { pstmt = DB.prepareStatement (sql, null); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MProduct product = new MProduct(Env.getCtx(), rs, null); addProduct (element, product); noProducts++; } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { log.log (Level.SEVERE, sql, e); } - try + finally { - if (pstmt != null) - pstmt.close (); + DB.close(rs, pstmt); + rs = null; pstmt = null; } - catch (Exception e) - { - pstmt = null; - } - + int mode = modeCombo.getSelectedIndex(); // No Products if (noProducts == 0 && mode == MODE_VIEW) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WFileImport.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WFileImport.java index 6b5f6d225a..b964cbc262 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WFileImport.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WFileImport.java @@ -235,21 +235,26 @@ public class WFileImport extends ADForm implements EventListener String sql = MRole.getDefault().addAccessSQL("SELECT Name FROM AD_ImpFormat", "AD_ImpFormat", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO); + 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()) pickFormat.appendItem(rs.getString(1), rs.getString(1)); - - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } pickFormat.setSelectedIndex(0); pickFormat.addEventListener(Events.ON_SELECT, this); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WAccountEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WAccountEditor.java index 60c82ce6d8..796168c1ab 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WAccountEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WAccountEditor.java @@ -155,9 +155,6 @@ public class WAccountEditor extends WEditor implements ContextMenuListener if (rs.next()) // only one C_ValidCombination_ID = 0; } - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WAssignmentEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WAssignmentEditor.java index 19270cb609..eef8e9d019 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WAssignmentEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WAssignmentEditor.java @@ -113,10 +113,11 @@ public class WAssignmentEditor extends WEditor implements ContextMenuListener { + " AND r.S_ResourceType_ID=rt.S_ResourceType_ID" + " and rt.C_UOM_ID=uom.C_UOM_ID", null); // + ResultSet rs = null; try { m_pstmt.setInt(1, S_ResourceAssignment_ID); - ResultSet rs = m_pstmt.executeQuery(); + rs = m_pstmt.executeQuery(); if (rs.next()) { StringBuilder sb = new StringBuilder(rs.getString(1)); @@ -127,12 +128,15 @@ public class WAssignmentEditor extends WEditor implements ContextMenuListener { } else getComponent().setText("<" + S_ResourceAssignment_ID + ">"); - rs.close(); } catch (Exception e) { log.log(Level.SEVERE, "", e); } + finally + { + DB.close(rs); + } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WLocatorEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WLocatorEditor.java index 1de51e252e..9738880335 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WLocatorEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WLocatorEditor.java @@ -357,7 +357,7 @@ public class WLocatorEditor extends WEditor implements EventListener, Pro int M_Locator_ID = 0; PreparedStatement pstmt = null; - + ResultSet rs = null; try { pstmt = DB.prepareStatement(finalSql, null); @@ -372,7 +372,7 @@ public class WLocatorEditor extends WEditor implements EventListener, Pro pstmt.setInt(index++, only_Product_ID); } - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { @@ -381,25 +381,17 @@ public class WLocatorEditor extends WEditor implements EventListener, Pro if (rs.next()) M_Locator_ID = 0; // more than one } - rs.close(); - pstmt.close(); - pstmt = null; } catch (SQLException ex) { log.log(Level.SEVERE, finalSql, ex); } - - try + finally { - if (pstmt != null) - pstmt.close(); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } - catch (SQLException ex1) - { - } - - pstmt = null; if (M_Locator_ID == 0) return false; diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WSearchEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WSearchEditor.java index f6a0ae9668..f9b3b5ef76 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WSearchEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WSearchEditor.java @@ -709,12 +709,12 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value m_keyColumnName = m_columnName; sql = new StringBuffer(); PreparedStatement pstmt = null; - + ResultSet rs = null; try { pstmt = DB.prepareStatement(query, null); pstmt.setString(1, m_keyColumnName); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { @@ -724,25 +724,17 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value m_tableName = rs.getString(1); sql.append("UPPER(").append(rs.getString(2)).append(") LIKE ").append(DB.TO_STRING(text)); } - - rs.close(); - pstmt.close(); - pstmt = null; } catch (SQLException ex) { log.log(Level.SEVERE, query, ex); } - - try + finally { - if (pstmt != null) - pstmt.close(); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } - catch (SQLException ex1) - { - } - pstmt = null; // if (sql.length() == 0) { diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoGeneralPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoGeneralPanel.java index 426676ceaa..32c70f7da5 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoGeneralPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoGeneralPanel.java @@ -269,11 +269,13 @@ public class InfoGeneralPanel extends InfoPanel implements EventListener 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()) { @@ -291,14 +293,18 @@ public class InfoGeneralPanel extends InfoPanel implements EventListener tableName = rs.getString(3); } } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); return false; } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // Miminum check if (m_queryColumns.size() == 0) @@ -340,9 +346,9 @@ public class InfoGeneralPanel extends InfoPanel implements EventListener 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); @@ -399,14 +405,18 @@ public class InfoGeneralPanel extends InfoPanel implements EventListener 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) { diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java index 429979282a..81ab4c0fbc 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java @@ -773,23 +773,28 @@ public abstract class InfoPanel extends Window implements EventListener, log.finer(countSql); m_count = -1; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(countSql, null); + pstmt = DB.prepareStatement(countSql, null); setParameters (pstmt, true); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) m_count = rs.getInt(1); - - rs.close(); - pstmt.close(); } catch (Exception e) { log.log(Level.SEVERE, countSql, e); m_count = -2; } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } if (log.isLoggable(Level.FINE)) log.fine("#" + m_count + " - " + (System.currentTimeMillis()-start) + "ms"); @@ -1079,32 +1084,26 @@ public abstract class InfoPanel extends Window implements EventListener, // String sql = "SELECT AD_Window_ID, PO_Window_ID FROM AD_Table WHERE TableName=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setString(1, tableName); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { m_SO_Window_ID = rs.getInt(1); m_PO_Window_ID = rs.getInt(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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FindWindow.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FindWindow.java index 06c040b196..51f73098ea 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FindWindow.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FindWindow.java @@ -1861,19 +1861,25 @@ public class FindWindow extends Window implements EventListener, ValueCha // 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) @@ -1920,9 +1926,11 @@ public class FindWindow extends Window implements EventListener, ValueCha StringBuilder retString = new StringBuilder(" M_Product_Category_ID IN ("); String sql = " SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category"; final Vector categories = new Vector(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); @@ -1931,8 +1939,6 @@ public class FindWindow extends Window implements EventListener, ValueCha } retString.append(getSubCategoriesString(productCategoryId, categories, subTreeRootParentId)) .append(") "); - rs.close(); - stmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); retString = new StringBuilder(); @@ -1940,6 +1946,11 @@ public class FindWindow extends Window implements EventListener, ValueCha log.log(Level.SEVERE, sql, e); retString = new StringBuilder(); } + finally{ + DB.close(rs,stmt); + rs = null; + stmt = null; + } return retString.toString(); } // getSubCategoryWhereClause diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/InfoSchedule.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/InfoSchedule.java index 2653797396..efd3b9e4e4 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/InfoSchedule.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/InfoSchedule.java @@ -268,20 +268,26 @@ public class InfoSchedule extends Window implements EventListener if (m_mAssignment.getS_Resource_ID() != 0) { String sql = "SELECT S_ResourceType_ID FROM S_Resource WHERE S_Resource_ID=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_mAssignment.getS_Resource_ID()); - ResultSet rs = pstmt.executeQuery(); + 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); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } } // Get Resource Types @@ -289,10 +295,12 @@ public class InfoSchedule extends Window implements EventListener "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)); @@ -300,13 +308,17 @@ public class InfoSchedule extends Window implements EventListener defaultValue = pp; fieldResourceType.appendItem(pp.getName(), pp.getKey()); } - 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) { int cnt = fieldResourceType.getItemCount(); for(int i = 0; i < cnt; i++) { @@ -340,11 +352,13 @@ public class InfoSchedule extends Window implements EventListener m_loading = true; fieldResource.getChildren().clear(); 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)); @@ -352,13 +366,17 @@ public class InfoSchedule extends Window implements EventListener defaultValue = pp; fieldResource.appendItem(pp.getName(), pp.getKey()); } - 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) { int cnt = fieldResource.getItemCount(); for(int i = 0; i < cnt; i++) { diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WAccountDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WAccountDialog.java index f82ab70caf..b945c58488 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WAccountDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WAccountDialog.java @@ -510,12 +510,14 @@ public final class WAccountDialog extends Window { log.fine("C_ValidCombination_ID=" + C_ValidCombination_ID); String sql = "SELECT * FROM C_ValidCombination WHERE C_ValidCombination_ID=? AND C_AcctSchema_ID=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, C_ValidCombination_ID); pstmt.setInt(2, C_AcctSchema_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { if (f_Alias != null) @@ -540,13 +542,17 @@ public final class WAccountDialog extends Window // f_Description.setValue (rs.getString("Description")); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } } // loadInfo /** @@ -909,25 +915,31 @@ public final class WAccountDialog extends Window log.fine("Check = " + sql.toString()); int IDvalue = 0; String Alias = 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_AD_Client_ID); pstmt.setInt(2, s_AcctSchema.getC_AcctSchema_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { IDvalue = rs.getInt(1); Alias = rs.getString(2); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); IDvalue = 0; } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } log.fine("ID=" + IDvalue + ", Alias=" + Alias); if (Alias == null) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WAssignmentDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WAssignmentDialog.java index 7868c38cc9..89707493f2 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WAssignmentDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WAssignmentDialog.java @@ -310,10 +310,12 @@ public class WAssignmentDialog extends Window implements EventListener + "FROM S_Resource r, S_ResourceType rt, C_UOM uom " + "WHERE r.S_ResourceType_ID=rt.S_ResourceType_ID AND rt.C_UOM_ID=uom.C_UOM_ID", "r", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO); + 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()) { StringBuilder sb = new StringBuilder (rs.getString(2)); @@ -325,13 +327,17 @@ public class WAssignmentDialog extends Window implements EventListener KeyNamePair value = new KeyNamePair (rs.getInt(4), rs.getString(5).trim()); m_lookup.put(key, value); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } } // Convert to Array KeyNamePair[] retValue = new KeyNamePair[m_lookup.size()]; diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocatorDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocatorDialog.java index 79ee5c72e7..7d370062aa 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocatorDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocatorDialog.java @@ -304,25 +304,28 @@ public class WLocatorDialog extends Window implements EventListener String SQL = MRole.getDefault().addAccessSQL( sql, "M_Warehouse", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO) + " ORDER BY 2"; - + 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 key = new KeyNamePair(rs.getInt(1), rs.getString(2)); lstWarehouse.appendItem(key.getName(), key); } - - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, SQL, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } log.fine("Warehouses=" + lstWarehouse.getItemCount()); @@ -442,12 +445,13 @@ public class WLocatorDialog extends Window implements EventListener String SQL = "SELECT M_Warehouse_ID, Value, Name, Separator, AD_Client_ID, AD_Org_ID " + "FROM M_Warehouse WHERE M_Warehouse_ID=?"; - + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(SQL, null); + pstmt = DB.prepareStatement(SQL, null); pstmt.setInt(1, M_Warehouse_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { @@ -458,13 +462,17 @@ public class WLocatorDialog extends Window implements EventListener m_AD_Client_ID = rs.getInt(5); m_AD_Org_ID = rs.getInt(6); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, SQL, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } } // getWarehouseInfo /** diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WRecordAccessDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WRecordAccessDialog.java index 496a7a7c8e..256b6e681a 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WRecordAccessDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WRecordAccessDialog.java @@ -119,33 +119,27 @@ public class WRecordAccessDialog extends Window implements EventListener sql = "SELECT * FROM AD_Record_Access " + "WHERE AD_Table_ID=? AND Record_ID=? AND AD_Client_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_AD_Table_ID); pstmt.setInt(2, m_Record_ID); pstmt.setInt(3, Env.getAD_Client_ID(Env.getCtx())); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) m_recordAccesss.add(new MRecordAccess(Env.getCtx(), rs, null)); - 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) - { + finally{ + DB.close(rs, pstmt); + rs = null; pstmt = null; } + log.fine("#" + m_recordAccesss.size()); setLine(0, false); } // dynInit diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WRecordInfo.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WRecordInfo.java index 847a76b285..d74e640af9 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WRecordInfo.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WRecordInfo.java @@ -238,33 +238,27 @@ public class WRecordInfo extends Window implements EventListener + "WHERE AD_Table_ID=? AND Record_ID=? " + "ORDER BY Updated DESC"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, dse.AD_Table_ID); pstmt.setInt (2, Record_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { addLine (rs.getInt(1), rs.getTimestamp(2), rs.getInt(3), rs.getString(4), rs.getString(5)); } - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java index db1e35a3b5..8888808de1 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java @@ -497,13 +497,15 @@ public class ZkReportViewer extends Window implements EventListener, ITab + "WHERE c.AD_Table_ID=? AND c.IsKey='Y'" + " AND et.AD_Language=? " + "ORDER BY 3"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_reportEngine.getPrintFormat().getAD_Table_ID()); if (trl) pstmt.setString(2, Env.getAD_Language(Env.getCtx())); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { String tableName = rs.getString(2); @@ -513,13 +515,18 @@ public class ZkReportViewer extends Window implements EventListener, ITab name += "/" + poName; comboDrill.appendItem(name, tableName); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } + if (comboDrill.getItemCount() == 1) { labelDrill.setVisible(false); @@ -551,11 +558,13 @@ public class ZkReportViewer extends Window implements EventListener, ITab + "ORDER BY Name", "AD_PrintFormat", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO); int AD_Table_ID = m_reportEngine.getPrintFormat().getAD_Table_ID(); + PreparedStatement pstmt = null; + ResultSet rs = null; 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()) { KeyNamePair pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); @@ -567,13 +576,17 @@ public class ZkReportViewer extends Window implements EventListener, ITab comboReport.setSelectedItem(li); } } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // IDEMPIERE-297 - Check for Table Access and Window Access for New Report if ( MRole.getDefault().isTableAccess(MPrintFormat.Table_ID, false) && MRole.getDefault().getWindowAccess(WINDOW_PRINTFORMAT)) @@ -1023,25 +1036,30 @@ public class ZkReportViewer extends Window implements EventListener, ITab if (!Env.isBaseLanguage(Env.getCtx(), "AD_Tab")) sql = "SELECT Name, TableName FROM AD_Tab_vt WHERE AD_Tab_ID=?" + " AND AD_Language='" + Env.getAD_Language(Env.getCtx()) + "' " + ASPFilter; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, AD_Tab_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); // if (rs.next()) { title = rs.getString(1); tableName = rs.getString(2); } - // - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } GridField[] findFields = null; if (tableName != null) diff --git a/org.adempiere.ui/src/org/compiere/apps/form/Charge.java b/org.adempiere.ui/src/org/compiere/apps/form/Charge.java index a4af4aac91..59c95259c5 100644 --- a/org.adempiere.ui/src/org/compiere/apps/form/Charge.java +++ b/org.adempiere.ui/src/org/compiere/apps/form/Charge.java @@ -72,11 +72,13 @@ public class Charge + " AND IsSummary='N'" + " AND C_Element_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, m_C_Element_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { Vector line = new Vector(4); @@ -88,13 +90,17 @@ public class Charge line.add(new Boolean(isExpenseType)); // 3-Expense 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; + } return data; } @@ -110,23 +116,28 @@ public class Charge String sql = "SELECT C_Element_ID " + "FROM C_AcctSchema_Element " + "WHERE ElementType='AC' AND C_AcctSchema_ID=?"; - + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_C_AcctSchema_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { m_C_Element_ID = rs.getInt(1); } - rs.close(); - pstmt.close(); } catch (SQLException exception) { log.log(Level.SEVERE, sql, exception); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } } public Vector getColumnNames() @@ -165,20 +176,26 @@ public class Charge String sql = "SELECT C_TaxCategory_ID FROM C_TaxCategory " + "WHERE IsDefault='Y' AND AD_Client_ID=?"; m_C_TaxCategory_ID = 0; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_AD_Client_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) m_C_TaxCategory_ID = rs.getInt(1); - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } } // dynInit /************************************************************************** diff --git a/org.adempiere.ui/src/org/compiere/apps/form/FactReconcile.java b/org.adempiere.ui/src/org/compiere/apps/form/FactReconcile.java index 6c53bcd78e..eab1c471bb 100644 --- a/org.adempiere.ui/src/org/compiere/apps/form/FactReconcile.java +++ b/org.adempiere.ui/src/org/compiere/apps/form/FactReconcile.java @@ -122,9 +122,11 @@ public class FactReconcile { log.fine("SQL=" + sql.toString()); + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), null); int i = 1; pstmt.setInt(i++, m_AD_Client_ID); @@ -149,7 +151,7 @@ public class FactReconcile { if(m_DateAcct2!=null) pstmt.setTimestamp(i++, m_DateAcct2); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { Vector line = new Vector(); @@ -170,13 +172,17 @@ public class FactReconcile { // data.add(line); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return data; } @@ -254,21 +260,27 @@ public class FactReconcile { + "WHERE ase.ElementType='AC' AND ase.AD_Client_ID=" + m_AD_Client_ID + ") " + "ORDER BY 2"; + 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()) { vector.add(new KeyNamePair(rs.getInt(1), rs.getString(2))); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return vector; } diff --git a/org.adempiere.ui/src/org/compiere/apps/form/InOutGen.java b/org.adempiere.ui/src/org/compiere/apps/form/InOutGen.java index b5a747eae9..bf5083a6c5 100644 --- a/org.adempiere.ui/src/org/compiere/apps/form/InOutGen.java +++ b/org.adempiere.ui/src/org/compiere/apps/form/InOutGen.java @@ -185,11 +185,13 @@ public class InOutGen extends GenForm int row = 0; miniTable.setRowCount(row); // Execute + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), null); pstmt.setInt(1, AD_Client_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); // while (rs.next()) { @@ -206,13 +208,17 @@ public class InOutGen extends GenForm // prepare next row++; } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // miniTable.autoSize(); // statusBar.setStatusDB(String.valueOf(miniTable.getRowCount())); diff --git a/org.adempiere.ui/src/org/compiere/apps/form/InvoiceGen.java b/org.adempiere.ui/src/org/compiere/apps/form/InvoiceGen.java index 575ad925c9..24b1629c7f 100644 --- a/org.adempiere.ui/src/org/compiere/apps/form/InvoiceGen.java +++ b/org.adempiere.ui/src/org/compiere/apps/form/InvoiceGen.java @@ -185,11 +185,13 @@ public class InvoiceGen extends GenForm int row = 0; miniTable.setRowCount(row); // Execute + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), null); pstmt.setInt(1, AD_Client_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); // while (rs.next()) { @@ -206,13 +208,17 @@ public class InvoiceGen extends GenForm // prepare next row++; } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); } + finally + { + DB.close(rs,pstmt); + rs = null; + pstmt = null; + } // miniTable.autoSize(); // statusBar.setStatusDB(String.valueOf(miniTable.getRowCount())); diff --git a/org.adempiere.ui/src/org/compiere/apps/form/Merge.java b/org.adempiere.ui/src/org/compiere/apps/form/Merge.java index 8c63e9908b..ae32e7bcce 100644 --- a/org.adempiere.ui/src/org/compiere/apps/form/Merge.java +++ b/org.adempiere.ui/src/org/compiere/apps/form/Merge.java @@ -112,7 +112,7 @@ public class Merge + ") AND c.ColumnSQL IS NULL " + "ORDER BY t.LoadSeq DESC"; PreparedStatement pstmt = null; - + ResultSet rs = null; try { @@ -121,7 +121,7 @@ public class Merge pstmt = DB.prepareStatement(sql, Trx.createTrxName()); pstmt.setString(1, ColumnName); pstmt.setString(2, ColumnName); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { String tName = rs.getString(1); @@ -135,9 +135,6 @@ public class Merge m_totalCount += count; } } - rs.close(); - pstmt.close(); - pstmt = null; // log.config("Success=" + success + " - " + ColumnName + " - From=" + from_ID + ",To=" + to_ID); @@ -173,17 +170,13 @@ public class Merge log.log(Level.SEVERE, ColumnName, ex); success = false; } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // Cleanup - try - { - if (pstmt != null) - pstmt.close(); - - } - catch (Exception ex) - { - } - pstmt = null; return success; } // merge diff --git a/org.adempiere.ui/src/org/compiere/apps/form/PayPrint.java b/org.adempiere.ui/src/org/compiere/apps/form/PayPrint.java index 04038e824c..ced8f39a0b 100644 --- a/org.adempiere.ui/src/org/compiere/apps/form/PayPrint.java +++ b/org.adempiere.ui/src/org/compiere/apps/form/PayPrint.java @@ -65,24 +65,30 @@ public class PayPrint { String sql = "SELECT C_PaySelection_ID, Name || ' - ' || TotalAmt FROM C_PaySelection " + "WHERE AD_Client_ID=? AND Processed='Y' AND IsActive='Y'" + "ORDER BY PayDate DESC"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, AD_Client_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); // while (rs.next()) { KeyNamePair pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); data.add(pp); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return data; } @@ -105,11 +111,13 @@ public class PayPrint { + " INNER JOIN C_Bank b ON (ba.C_Bank_ID=b.C_Bank_ID)" + " INNER JOIN C_Currency c ON (ba.C_Currency_ID=c.C_Currency_ID) " + "WHERE ps.C_PaySelection_ID=? AND ps.Processed='Y' AND ba.IsActive='Y'"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, C_PaySelection_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { m_C_BankAccount_ID = rs.getInt(1); @@ -127,13 +135,17 @@ public class PayPrint { m_PaymentExportClass = null; log.log(Level.SEVERE, "No active BankAccount for C_PaySelection_ID=" + C_PaySelection_ID); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } } // loadPaySelectInfo /** @@ -151,24 +163,30 @@ public class PayPrint { + " AND " + info.KeyColumn + " IN (SELECT PaymentRule FROM C_PaySelectionCheck WHERE C_PaySelection_ID=?) " + info.Query.substring(info.Query.indexOf(" ORDER BY")); + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, C_PaySelection_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); // while (rs.next()) { ValueNamePair pp = new ValueNamePair(rs.getString(2), rs.getString(3)); data.add(pp); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } if (data.size() == 0) log.config("PaySel=" + C_PaySelection_ID + ", BAcct=" + m_C_BankAccount_ID + " - " + sql); @@ -191,21 +209,27 @@ public class PayPrint { String sql = "SELECT COUNT(*) " + "FROM C_PaySelectionCheck " + "WHERE C_PaySelection_ID=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, C_PaySelection_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); // if (rs.next()) noPayments = String.valueOf(rs.getInt(1)); - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // DocumentNo sql = "SELECT CurrentNext " @@ -213,10 +237,10 @@ public class PayPrint { + "WHERE C_BankAccount_ID=? AND PaymentRule=? AND IsActive='Y'"; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_C_BankAccount_ID); pstmt.setString(2, PaymentRule); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); // if (rs.next()) documentNo = new Integer(rs.getInt(1)); @@ -226,13 +250,17 @@ public class PayPrint { + m_C_BankAccount_ID + " AND PaymentRule=" + PaymentRule); msg = "VPayPrintNoDoc"; } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return msg; } // loadPaymentRuleInfo diff --git a/org.adempiere.ui/src/org/compiere/apps/form/PaySelect.java b/org.adempiere.ui/src/org/compiere/apps/form/PaySelect.java index 93c82d4ed2..3e89ec34c2 100644 --- a/org.adempiere.ui/src/org/compiere/apps/form/PaySelect.java +++ b/org.adempiere.ui/src/org/compiere/apps/form/PaySelect.java @@ -92,10 +92,12 @@ public class PaySelect + " AND EXISTS (SELECT * FROM C_BankAccountDoc d WHERE d.C_BankAccount_ID=ba.C_BankAccount_ID AND d.IsActive='Y' ) " + "ORDER BY 2", "b", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RW); + 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()) { boolean transfers = false; @@ -104,13 +106,17 @@ public class PaySelect rs.getBigDecimal(5), transfers); data.add(bi); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return data; } @@ -131,23 +137,28 @@ public class PaySelect + " AND (i.IsSOTrx='N' OR (i.IsSOTrx='Y' AND i.PaymentRule='D'))" + " AND i.IsPaid<>'Y') " + "ORDER BY 2"; - + 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()) { pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); data.add(pp); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return data; } @@ -157,6 +168,8 @@ public class PaySelect ArrayList data = new ArrayList(); String sql = null; /**Document type**/ + PreparedStatement pstmt = null; + ResultSet rs = null; try { sql = MRole.getDefault().addAccessSQL( @@ -165,22 +178,26 @@ public class PaySelect KeyNamePair dt = new KeyNamePair(0, ""); data.add(dt); - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_AD_Client_ID); // Client - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { dt = new KeyNamePair(rs.getInt(1), rs.getString(2)); data.add(dt); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return data; } @@ -256,24 +273,30 @@ public class PaySelect + " AND " + info.KeyColumn + " IN (SELECT PaymentRule FROM C_BankAccountDoc WHERE C_BankAccount_ID=?) " + info.Query.substring(info.Query.indexOf(" ORDER BY")); + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, bi.C_BankAccount_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); ValueNamePair vp = null; while (rs.next()) { vp = new ValueNamePair(rs.getString(2), rs.getString(3)); // returns also not active data.add(vp); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return data; } @@ -313,10 +336,12 @@ public class PaySelect log.finest(sql + " - C_Currency_ID=" + bi.C_Currency_ID + ", C_BPartner_ID=" + C_BPartner_ID + ", C_doctype_id=" + c_doctype_id ); // Get Open Invoices + PreparedStatement pstmt = null; + ResultSet rs = null; try { int index = 1; - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setTimestamp(index++, payDate); // DiscountAmt pstmt.setInt(index++, bi.C_Currency_ID); // DueAmt pstmt.setTimestamp(index++, payDate); @@ -332,15 +357,19 @@ public class PaySelect if (c_doctype_id != 0) //Document type pstmt.setInt(index++, c_doctype_id ); // - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); miniTable.loadTable(rs); - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } } // loadTableInfo /** diff --git a/org.adempiere.ui/src/org/compiere/apps/form/TrxMaterial.java b/org.adempiere.ui/src/org/compiere/apps/form/TrxMaterial.java index 68ac076dce..d80d4d50a6 100644 --- a/org.adempiere.ui/src/org/compiere/apps/form/TrxMaterial.java +++ b/org.adempiere.ui/src/org/compiere/apps/form/TrxMaterial.java @@ -173,20 +173,26 @@ public class TrxMaterial { // Get Parent ID int parentID = 0; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(SQL, null); + pstmt = DB.prepareStatement(SQL, null); pstmt.setInt(1, lineID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) parentID = rs.getInt(1); - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, SQL, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } query = MQuery.getEqualQuery(ColumnName, parentID); log.config("AD_Window_ID=" + AD_Window_ID + " - " + query); if (parentID == 0) diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFromPackageShipment.java b/org.adempiere.ui/src/org/compiere/grid/CreateFromPackageShipment.java index 1745137391..15720979b6 100644 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFromPackageShipment.java +++ b/org.adempiere.ui/src/org/compiere/grid/CreateFromPackageShipment.java @@ -65,11 +65,13 @@ public abstract class CreateFromPackageShipment extends CreateFrom sqlStmt.append("FROM M_PACKAGELINES_AVAIL_V "); sqlStmt.append("WHERE M_InOut_ID = ? "); + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sqlStmt.toString(), null); + pstmt = DB.prepareStatement(sqlStmt.toString(), null); pstmt.setInt(1, M_InOut_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { Vector line = new Vector(6); @@ -84,13 +86,17 @@ public abstract class CreateFromPackageShipment extends CreateFrom data.add(line); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sqlStmt.toString(), e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return data; } diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFromRMA.java b/org.adempiere.ui/src/org/compiere/grid/CreateFromRMA.java index 15151dbbaa..a2f1769922 100644 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFromRMA.java +++ b/org.adempiere.ui/src/org/compiere/grid/CreateFromRMA.java @@ -86,12 +86,14 @@ public abstract class CreateFromRMA extends CreateFrom { sqlStmt.append("WHERE M_InOut_ID=? "); sqlStmt.append("AND iol.M_InOutLine_ID NOT IN (SELECT rmal.M_InOutLine_ID FROM M_RMALine rmal WHERE rmal.M_RMA_ID=?)"); + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sqlStmt.toString(), null); + pstmt = DB.prepareStatement(sqlStmt.toString(), null); pstmt.setInt(1, M_InOut_ID); pstmt.setInt(2, M_RMA_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { Vector line = new Vector(7); @@ -111,13 +113,17 @@ public abstract class CreateFromRMA extends CreateFrom { data.add(line); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sqlStmt.toString(), e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return data; } diff --git a/org.adempiere.ui/src/org/compiere/grid/PaymentForm.java b/org.adempiere.ui/src/org/compiere/grid/PaymentForm.java index 391020c50d..812624dfdf 100644 --- a/org.adempiere.ui/src/org/compiere/grid/PaymentForm.java +++ b/org.adempiere.ui/src/org/compiere/grid/PaymentForm.java @@ -176,23 +176,29 @@ public abstract class PaymentForm implements IPaymentForm { String SQL = "SELECT C_Currency_ID, ISO_Code FROM C_Currency " + "WHERE (IsEMUMember='Y' AND EMUEntryDate