IDEMPIERE-568 Review proper closing of JDBC statements and resultsets

This commit is contained in:
Richard Morales 2013-02-20 20:31:16 -05:00
parent b7acdff746
commit 65a9dc9adc
26 changed files with 184 additions and 204 deletions

View File

@ -97,13 +97,13 @@ public class InOutGenerateRMA extends SvrProcess
+ "AND T_Selection.AD_PInstance_ID=? "; + "AND T_Selection.AD_PInstance_ID=? ";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, Env.getAD_Client_ID(getCtx())); pstmt.setInt(1, Env.getAD_Client_ID(getCtx()));
pstmt.setInt(2, getAD_PInstance_ID()); pstmt.setInt(2, getAD_PInstance_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
@ -116,14 +116,8 @@ public class InOutGenerateRMA extends SvrProcess
} }
finally finally
{ {
try DB.close(rs,pstmt);
{ rs = null;pstmt = null;
pstmt.close();
}
catch (Exception ex)
{
log.log(Level.SEVERE, "Could not close prepared statement");
}
} }
StringBuilder msgreturn = new StringBuilder("@Created@ = ").append(m_created); StringBuilder msgreturn = new StringBuilder("@Created@ = ").append(m_created);

View File

@ -92,13 +92,13 @@ public class InvoiceGenerateRMA extends SvrProcess
+ "AND T_Selection.AD_PInstance_ID=? "; + "AND T_Selection.AD_PInstance_ID=? ";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, Env.getAD_Client_ID(getCtx())); pstmt.setInt(1, Env.getAD_Client_ID(getCtx()));
pstmt.setInt(2, getAD_PInstance_ID()); pstmt.setInt(2, getAD_PInstance_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
@ -111,14 +111,8 @@ public class InvoiceGenerateRMA extends SvrProcess
} }
finally finally
{ {
try DB.close(rs,pstmt);
{ rs = null;pstmt = null;
pstmt.close();
}
catch (Exception ex)
{
log.log(Level.SEVERE, "Could not close prepared statement");
}
} }
StringBuilder msgreturn = new StringBuilder("@Created@ = ").append(m_created); StringBuilder msgreturn = new StringBuilder("@Created@ = ").append(m_created);
return msgreturn.toString(); return msgreturn.toString();

View File

@ -85,21 +85,23 @@ public class PrepareMigrationScripts extends SvrProcess {
.append(fileName.get(i)) .append(fileName.get(i))
.append("]. Finding out if the script has or hasn't been applied yet..."); .append("]. Finding out if the script has or hasn't been applied yet...");
log.fine(msglog.toString()); log.fine(msglog.toString());
PreparedStatement pstmt = null;
ResultSet rs = null;
try { try {
// First of all, check if the script hasn't been applied yet... // First of all, check if the script hasn't been applied yet...
String checkScript = "select ad_migrationscript_id from ad_migrationscript where name = ?"; String checkScript = "select ad_migrationscript_id from ad_migrationscript where name = ?";
PreparedStatement pstmt = DB.prepareStatement(checkScript, this pstmt = DB.prepareStatement(checkScript, this
.get_TrxName()); .get_TrxName());
pstmt.setString(1, fileName.get(i)); pstmt.setString(1, fileName.get(i));
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) { if (rs.next()) {
msglog = new StringBuilder("Script ").append(fileName.get(i)) msglog = new StringBuilder("Script ").append(fileName.get(i))
.append(" already in the database"); .append(" already in the database");
log.warning(msglog.toString()); log.warning(msglog.toString());
pstmt.close();
continue; continue;
} }
pstmt.close(); DB.close(pstmt);
pstmt = null;
// first use a Scanner to get each line // first use a Scanner to get each line
Scanner scanner = new Scanner(dirList[i]); Scanner scanner = new Scanner(dirList[i]);
StringBuilder body = new StringBuilder(); StringBuilder body = new StringBuilder();
@ -213,7 +215,8 @@ public class PrepareMigrationScripts extends SvrProcess {
pstmt.setTimestamp(15, ts); pstmt.setTimestamp(15, ts);
pstmt.setTimestamp(16, ts); pstmt.setTimestamp(16, ts);
int result = pstmt.executeUpdate(); int result = pstmt.executeUpdate();
pstmt.close(); DB.close(pstmt);
pstmt = null;
if (result > 0) if (result > 0)
log.info("Header inserted. Now inserting the script body"); log.info("Header inserted. Now inserting the script body");
else { else {
@ -227,7 +230,8 @@ public class PrepareMigrationScripts extends SvrProcess {
pstmt.setBytes(1, body.toString().getBytes()); pstmt.setBytes(1, body.toString().getBytes());
pstmt.setInt(2, seqID); pstmt.setInt(2, seqID);
result = pstmt.executeUpdate(); result = pstmt.executeUpdate();
pstmt.close(); DB.close(pstmt);
pstmt = null;
if (result > 0) if (result > 0)
log.info("Script Body inserted."); log.info("Script Body inserted.");
else { else {
@ -245,6 +249,13 @@ public class PrepareMigrationScripts extends SvrProcess {
} catch (Exception ex) { } catch (Exception ex) {
log.severe(ex.getMessage()); log.severe(ex.getMessage());
} }
finally
{
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
} }
return "Sucess"; return "Sucess";
} }

View File

@ -80,11 +80,12 @@ public class UpdateRoleMenu extends SvrProcess
String sqlStmt = "SELECT U_WebMenu_ID, IsActive FROM U_WebMenu"; String sqlStmt = "SELECT U_WebMenu_ID, IsActive FROM U_WebMenu";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement(sqlStmt, get_TrxName()); pstmt = DB.prepareStatement(sqlStmt, get_TrxName());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
@ -101,17 +102,9 @@ public class UpdateRoleMenu extends SvrProcess
} }
finally finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
{ rs = null;
try pstmt = null;
{
pstmt.close();
}
catch (Exception ex)
{
log.log(Level.SEVERE, "Could not close prepared statement");
}
}
} }
return "Role updated successfully"; return "Role updated successfully";

View File

@ -225,7 +225,6 @@ public class PaySelectionCreateFrom extends SvrProcess
PayAmt, PayAmt.subtract(DiscountAmt), DiscountAmt); PayAmt, PayAmt.subtract(DiscountAmt), DiscountAmt);
if (!pselLine.save()) if (!pselLine.save())
{ {
pstmt.close();
throw new IllegalStateException ("Cannot save MPaySelectionLine"); throw new IllegalStateException ("Cannot save MPaySelectionLine");
} }
} }

View File

@ -80,13 +80,13 @@ public final class ProcessUtil {
public static boolean startDatabaseProcedure (ProcessInfo processInfo, String ProcedureName, Trx trx, boolean managedTrx) { public static boolean startDatabaseProcedure (ProcessInfo processInfo, String ProcedureName, Trx trx, boolean managedTrx) {
String sql = "{call " + ProcedureName + "(?)}"; String sql = "{call " + ProcedureName + "(?)}";
String trxName = trx != null ? trx.getTrxName() : null; String trxName = trx != null ? trx.getTrxName() : null;
CallableStatement cstmt = null;
try try
{ {
//hengsin, add trx support, updateable support. //hengsin, add trx support, updateable support.
CallableStatement cstmt = DB.prepareCall(sql, ResultSet.CONCUR_UPDATABLE, trxName); cstmt = DB.prepareCall(sql, ResultSet.CONCUR_UPDATABLE, trxName);
cstmt.setInt(1, processInfo.getAD_PInstance_ID()); cstmt.setInt(1, processInfo.getAD_PInstance_ID());
cstmt.executeUpdate(); cstmt.executeUpdate();
cstmt.close();
if (trx != null && trx.isActive() && managedTrx) if (trx != null && trx.isActive() && managedTrx)
{ {
trx.commit(true); trx.commit(true);
@ -105,6 +105,8 @@ public final class ProcessUtil {
} }
finally finally
{ {
DB.close(cstmt);
cstmt = null;
if (trx != null && managedTrx) if (trx != null && managedTrx)
trx.close(); trx.close();
} }

View File

@ -749,9 +749,6 @@ public class CreateAdempiere
log.finest("# " + no); log.finest("# " + no);
} }
// //
stmt.close();
stmt = null;
//
if (batch) if (batch)
conn.commit(); conn.commit();
// //
@ -774,17 +771,11 @@ public class CreateAdempiere
msg += "\n=>" + cmd; msg += "\n=>" + cmd;
log.log(Level.SEVERE, msg); log.log(Level.SEVERE, msg);
} }
// Error clean up finally
try
{ {
if (stmt != null) DB.close(stmt);
stmt.close(); stmt = null;
} }
catch (SQLException e1)
{
log.log(Level.SEVERE, "close statement", e1);
}
stmt = null;
return false; return false;
} // execureCommands } // execureCommands

View File

@ -179,10 +179,7 @@ public class StatementProxy implements InvocationHandler {
if (close) return; if (close) return;
try { try {
if (p_stmt != null) DB.close(p_stmt);
{
p_stmt.close();
}
} finally { } finally {
if (m_conn != null) if (m_conn != null)
{ {
@ -194,6 +191,7 @@ public class StatementProxy implements InvocationHandler {
{} {}
} }
m_conn = null; m_conn = null;
p_stmt = null;
close = true; close = true;
} }
} // close } // close
@ -222,6 +220,9 @@ public class StatementProxy implements InvocationHandler {
finally finally
{ {
DB.close(rs); DB.close(rs);
rs = null;
DB.close(rowSet);
rowSet = null;
} }
return rowSet; return rowSet;
} // local_getRowSet } // local_getRowSet

View File

@ -97,16 +97,11 @@ public class MDepreciationConvention extends X_A_Depreciation_Convention
cs.setInt(6, Period); cs.setInt(6, Period);
cs.execute(); cs.execute();
retValue = cs.getBigDecimal(1); retValue = cs.getBigDecimal(1);
cs.close();
} catch (Exception e) { } catch (Exception e) {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
finally { finally {
try { DB.close(cs);
if (cs != null) cs.close();
} catch (SQLException e) {
log.log(Level.FINEST, "Error", e);
}
cs = null; cs = null;
} }
} }

View File

@ -178,7 +178,6 @@ public class MDepreciationMethod extends X_A_Depreciation_Method
cs.setInt(6, A_Asset_Acct_ID); cs.setInt(6, A_Asset_Acct_ID);
cs.execute(); cs.execute();
retValue = cs.getBigDecimal(1); retValue = cs.getBigDecimal(1);
cs.close();
} }
catch (SQLException e) catch (SQLException e)
{ {

View File

@ -20,6 +20,7 @@ import java.sql.ResultSet;
import java.util.Properties; import java.util.Properties;
import org.adempiere.exceptions.AdempiereException; import org.adempiere.exceptions.AdempiereException;
import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
/** /**
@ -223,16 +224,18 @@ public class MElementValue extends X_C_ElementValue
// //
// Check Valid Combinations - teo_sarca FR [ 1883533 ] // Check Valid Combinations - teo_sarca FR [ 1883533 ]
String whereClause = MAccount.COLUMNNAME_Account_ID+"=?"; String whereClause = MAccount.COLUMNNAME_Account_ID+"=?";
POResultSet<MAccount> rs = new Query(getCtx(), I_C_ValidCombination.Table_Name, whereClause, get_TrxName()) POResultSet<MAccount> rs = null;
.setParameters(get_ID())
.scroll();
try { try {
rs = new Query(getCtx(), I_C_ValidCombination.Table_Name, whereClause, get_TrxName())
.setParameters(get_ID())
.scroll();
while(rs.hasNext()) { while(rs.hasNext()) {
rs.next().deleteEx(true); rs.next().deleteEx(true);
} }
} }
finally { finally {
rs.close(); DB.close(rs);
rs = null;
} }
} }
return true; return true;

View File

@ -177,14 +177,15 @@ public class MSequence extends X_AD_Sequence
// get ID from http site // get ID from http site
retValue = getNextOfficialID_HTTP(TableName); retValue = getNextOfficialID_HTTP(TableName);
if (retValue > 0) { if (retValue > 0) {
PreparedStatement updateSQL; PreparedStatement updateSQL = null;
updateSQL = conn.prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = ? + 1 WHERE AD_Sequence_ID = ?");
try { try {
updateSQL = conn.prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = ? + 1 WHERE AD_Sequence_ID = ?");
updateSQL.setInt(1, retValue); updateSQL.setInt(1, retValue);
updateSQL.setInt(2, AD_Sequence_ID); updateSQL.setInt(2, AD_Sequence_ID);
updateSQL.executeUpdate(); updateSQL.executeUpdate();
} finally { } finally {
updateSQL.close(); DB.close(updateSQL);
updateSQL = null;
} }
} }
gotFromHTTP = true; gotFromHTTP = true;
@ -206,14 +207,15 @@ public class MSequence extends X_AD_Sequence
// get ID from http site // get ID from http site
retValue = getNextProjectID_HTTP(TableName); retValue = getNextProjectID_HTTP(TableName);
if (retValue > 0) { if (retValue > 0) {
PreparedStatement updateSQL; PreparedStatement updateSQL = null;
updateSQL = conn.prepareStatement("UPDATE AD_Sequence SET CurrentNext = GREATEST(CurrentNext, ? + 1) WHERE AD_Sequence_ID = ?");
try { try {
updateSQL = conn.prepareStatement("UPDATE AD_Sequence SET CurrentNext = GREATEST(CurrentNext, ? + 1) WHERE AD_Sequence_ID = ?");
updateSQL.setInt(1, retValue); updateSQL.setInt(1, retValue);
updateSQL.setInt(2, AD_Sequence_ID); updateSQL.setInt(2, AD_Sequence_ID);
updateSQL.executeUpdate(); updateSQL.executeUpdate();
} finally { } finally {
updateSQL.close(); DB.close(updateSQL);
updateSQL = null;
} }
} }
gotFromHTTP = true; gotFromHTTP = true;
@ -222,23 +224,25 @@ public class MSequence extends X_AD_Sequence
} }
if (! gotFromHTTP) { if (! gotFromHTTP) {
PreparedStatement updateSQL; PreparedStatement updateSQL = null;
int incrementNo = rs.getInt(3); try
if (adempiereSys) { {
updateSQL = conn int incrementNo = rs.getInt(3);
.prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = CurrentNextSys + ? WHERE AD_Sequence_ID = ?"); if (adempiereSys) {
retValue = rs.getInt(2); updateSQL = conn
} else { .prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = CurrentNextSys + ? WHERE AD_Sequence_ID = ?");
updateSQL = conn retValue = rs.getInt(2);
.prepareStatement("UPDATE AD_Sequence SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ?"); } else {
retValue = rs.getInt(1); updateSQL = conn
} .prepareStatement("UPDATE AD_Sequence SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ?");
try { retValue = rs.getInt(1);
}
updateSQL.setInt(1, incrementNo); updateSQL.setInt(1, incrementNo);
updateSQL.setInt(2, AD_Sequence_ID); updateSQL.setInt(2, AD_Sequence_ID);
updateSQL.executeUpdate(); updateSQL.executeUpdate();
} finally { } finally {
updateSQL.close(); DB.close(updateSQL);
updateSQL = null;
} }
} }
@ -263,14 +267,10 @@ public class MSequence extends X_AD_Sequence
finally finally
{ {
DB.close(rs, pstmt); DB.close(rs, pstmt);
pstmt = null; pstmt = null;rs = null;
rs = null; DB.close(timeoutStatement);
if (timeoutStatement != null){ timeoutStatement = null;
try {
timeoutStatement.close();
}catch(Exception e){}
timeoutStatement = null;
}
if (conn != null) if (conn != null)
{ {
try { try {
@ -478,6 +478,7 @@ public class MSequence extends X_AD_Sequence
finally finally
{ {
DB.close(updateSQL); DB.close(updateSQL);
updateSQL = null;
} }
} }
else else
@ -516,13 +517,12 @@ public class MSequence extends X_AD_Sequence
finally finally
{ {
DB.close(rs, pstmt); DB.close(rs, pstmt);
pstmt = null;rs = null;
DB.close(timeoutStatement);
timeoutStatement = null;
// Finish // Finish
try try
{ {
if (timeoutStatement != null) {
timeoutStatement.close();
timeoutStatement = null;
}
if (trx == null && conn != null) { if (trx == null && conn != null) {
conn.close(); conn.close();
conn = null; conn = null;

View File

@ -85,18 +85,23 @@ public class FinReportJasper extends FinReport
if (proc.getProcedureName() != null && proc.getProcedureName().length() > 0) { if (proc.getProcedureName() != null && proc.getProcedureName().length() > 0) {
// execute on this thread/connection // execute on this thread/connection
String sql = "{call " + proc.getProcedureName() + "(?)}"; String sql = "{call " + proc.getProcedureName() + "(?)}";
CallableStatement cstmt = null;
try try
{ {
CallableStatement cstmt = DB.prepareCall(sql); // ro?? cstmt = DB.prepareCall(sql); // ro??
cstmt.setInt(1, getAD_PInstance_ID()); cstmt.setInt(1, getAD_PInstance_ID());
cstmt.executeUpdate(); cstmt.executeUpdate();
cstmt.close();
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
poInfo.setSummary (Msg.getMsg(Env.getCtx(), "ProcessRunError") + " " + e.getLocalizedMessage()); poInfo.setSummary (Msg.getMsg(Env.getCtx(), "ProcessRunError") + " " + e.getLocalizedMessage());
} }
finally
{
DB.close(cstmt);
cstmt = null;
}
} }
// TODO - allow java class preprocess if the classname <> ProcessUtil.JASPER_STARTER_CLASS // TODO - allow java class preprocess if the classname <> ProcessUtil.JASPER_STARTER_CLASS

View File

@ -1056,6 +1056,7 @@ public final class DB
} }
// Always close cursor // Always close cursor
close(cs); close(cs);
cs = null;
} }
return no; return no;
} // executeUpdate } // executeUpdate
@ -1121,9 +1122,8 @@ public final class DB
} }
finally finally
{ {
if (rs != null) close(rs.getStatement());
rs.getStatement().close(); close(rs);rs = null;
DB.close(rs);
} }
} }
timeoutStatement = conn.createStatement(); timeoutStatement = conn.createStatement();
@ -1134,12 +1134,8 @@ public final class DB
} }
} catch (SQLException e) {} } catch (SQLException e) {}
finally{ finally{
if (timeoutStatement != null) { DB.close(timeoutStatement);
try { timeoutStatement = null;
timeoutStatement.close();
} catch (Exception e) {}
timeoutStatement = null;
}
} }
} }
else else
@ -1193,15 +1189,12 @@ public final class DB
} catch (SQLException e) { } catch (SQLException e) {
} }
finally{ finally{
if (timeoutStatement != null) { close(timeoutStatement);
try {
timeoutStatement.close();
} catch (Exception e) {}
timeoutStatement = null; timeoutStatement = null;
}
} }
} }
DB.close(cs); close(cs);
cs = null;
} }
return no; return no;
} }

View File

@ -4,6 +4,7 @@ import org.compiere.model.MAssetAddition;
import org.compiere.model.POResultSet; import org.compiere.model.POResultSet;
import org.compiere.model.Query; import org.compiere.model.Query;
import org.compiere.process.SvrProcess; import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
/** /**
@ -21,11 +22,11 @@ public class A_Asset_Addition_ProcessAll extends SvrProcess
// //
String whereClause = "AD_Client_ID=? AND IsActive=?" String whereClause = "AD_Client_ID=? AND IsActive=?"
+" AND "+MAssetAddition.COLUMNNAME_Processed+"=?"; +" AND "+MAssetAddition.COLUMNNAME_Processed+"=?";
POResultSet<MAssetAddition> POResultSet<MAssetAddition> rs = null;
rs = new Query(getCtx(), MAssetAddition.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{getAD_Client_ID(), "N", "N"})
.scroll();
try { try {
rs = new Query(getCtx(), MAssetAddition.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{getAD_Client_ID(), "N", "N"})
.scroll();
while (rs.hasNext()) { while (rs.hasNext()) {
MAssetAddition a = rs.next(); MAssetAddition a = rs.next();
boolean ret = a.processIt(MAssetAddition.DOCACTION_Complete); boolean ret = a.processIt(MAssetAddition.DOCACTION_Complete);
@ -36,7 +37,7 @@ public class A_Asset_Addition_ProcessAll extends SvrProcess
} }
} }
finally { finally {
rs.close(); rs = null; DB.close(rs); rs = null;
} }
// //
return "OK/Error: "+cnt_ok+"/"+cnt_err; return "OK/Error: "+cnt_ok+"/"+cnt_err;

View File

@ -78,8 +78,8 @@ public class SQLStatementElementHandler extends AbstractElementHandler {
int n = stmt.executeUpdate (sql); int n = stmt.executeUpdate (sql);
log.info("Executed SQL Statement for PostgreSQL: "+ getStringValue(element,"statement") + " ReturnValue="+n); log.info("Executed SQL Statement for PostgreSQL: "+ getStringValue(element,"statement") + " ReturnValue="+n);
} finally { } finally {
if (stmt != null) DB.close(stmt);
stmt.close(); stmt = null;
} }
} }
@ -105,6 +105,7 @@ public class SQLStatementElementHandler extends AbstractElementHandler {
logImportDetail (ctx, impDetail, 0, "SQLStatement",1,"Execute"); logImportDetail (ctx, impDetail, 0, "SQLStatement",1,"Execute");
} finally { } finally {
DB.close(pstmt); DB.close(pstmt);
pstmt = null;
} }
} }

View File

@ -232,26 +232,21 @@ public class VSQLProcess extends CPanel
log.log(Level.SEVERE, "process statement: " + sql + " - " + e.toString()); log.log(Level.SEVERE, "process statement: " + sql + " - " + e.toString());
result.append("===> ").append(e.toString()); result.append("===> ").append(e.toString());
} }
finally
{
DB.close(stmt);
stmt = null;
try
{
conn.close();
}
catch (SQLException e2)
{
log.log(Level.SEVERE, "processStatement - close connection", e2);
}
conn = null;
}
// Clean up
try
{
stmt.close();
}
catch (SQLException e1)
{
log.log(Level.SEVERE, "processStatement - close statement", e1);
}
stmt = null;
try
{
conn.close();
}
catch (SQLException e2)
{
log.log(Level.SEVERE, "processStatement - close connection", e2);
}
conn = null;
// //
result.append(Env.NL); result.append(Env.NL);
return result.toString(); return result.toString();

View File

@ -779,14 +779,7 @@ public final class Find extends CDialog
public void dispose() public void dispose()
{ {
log.config(""); log.config("");
DB.close(m_pstmt);
// Find SQL
if (m_pstmt != null)
{
try {
m_pstmt.close();
} catch (SQLException e) {}
}
m_pstmt = null; m_pstmt = null;
// Remove action listener from custom fields - teo_sarca [ 1709292 ] // Remove action listener from custom fields - teo_sarca [ 1709292 ]

View File

@ -968,17 +968,22 @@ public final class VAccountDialog extends CDialog
sql.append("'").append(f_Alias.getValue()).append("'"); sql.append("'").append(f_Alias.getValue()).append("'");
sql.append(" WHERE C_ValidCombination_ID=").append(IDvalue); sql.append(" WHERE C_ValidCombination_ID=").append(IDvalue);
int i = 0; int i = 0;
PreparedStatement stmt = null;
try try
{ {
java.sql.PreparedStatement stmt = DB.prepareStatement(sql.toString(), stmt = DB.prepareStatement(sql.toString(),
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE, null); ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE, null);
i = stmt.executeUpdate(); i = stmt.executeUpdate();
stmt.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, sql.toString(), e); log.log(Level.SEVERE, sql.toString(), e);
} }
finally
{
DB.close(stmt);
stmt = null;
}
if (i == 0) if (i == 0)
ADialog.error(m_WindowNo, this, "AccountNotUpdated"); ADialog.error(m_WindowNo, this, "AccountNotUpdated");
} }

View File

@ -188,8 +188,8 @@ public class VAssignment extends JComponent
{ {
try try
{ {
if (m_pstmt != null) DB.close(m_pstmt);
m_pstmt.close(); m_pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -238,26 +238,20 @@ public class WSQLProcess extends ADForm implements EventListener<Event>
log.log(Level.SEVERE, "process statement: " + sql + " - " + exception); log.log(Level.SEVERE, "process statement: " + sql + " - " + exception);
result.append("===> ").append(exception); result.append("===> ").append(exception);
} }
finally
// Clean up
try
{ {
stmt.close(); DB.close(stmt);
} stmt = null;
catch (SQLException e1) try
{ {
log.log(Level.SEVERE, "processStatement - close statement", e1); conn.close();
} }
stmt = null; catch (SQLException e2)
try {
{ log.log(Level.SEVERE, "processStatement - close connection", e2);
conn.close(); }
} conn = null;
catch (SQLException e2) }
{
log.log(Level.SEVERE, "processStatement - close connection", e2);
}
conn = null;
// //
result.append(Env.NL); result.append(Env.NL);
return result.toString(); return result.toString();

View File

@ -1789,15 +1789,9 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
log.config(""); log.config("");
// Find SQL // Find SQL
if (m_pstmt != null) DB.close(m_pstmt);
{
try {
m_pstmt.close();
} catch (SQLException e) {}
}
m_pstmt = null; m_pstmt = null;
// TargetFields // TargetFields
if (m_targetFields != null) if (m_targetFields != null)
m_targetFields.clear(); m_targetFields.clear();

View File

@ -956,17 +956,22 @@ public final class WAccountDialog extends Window
sql.append("'").append(f_Alias.getValue()).append("'"); sql.append("'").append(f_Alias.getValue()).append("'");
sql.append(" WHERE C_ValidCombination_ID=").append(IDvalue); sql.append(" WHERE C_ValidCombination_ID=").append(IDvalue);
int i = 0; int i = 0;
PreparedStatement stmt = null;
try try
{ {
java.sql.PreparedStatement stmt = DB.prepareStatement(sql.toString(), stmt = DB.prepareStatement(sql.toString(),
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE, null); ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE, null);
i = stmt.executeUpdate(); i = stmt.executeUpdate();
stmt.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, sql.toString(), e); log.log(Level.SEVERE, sql.toString(), e);
} }
finally
{
DB.close(stmt);
stmt = null;
}
if (i == 0) if (i == 0)
FDialog.error(m_WindowNo, this, "AccountNotUpdated"); FDialog.error(m_WindowNo, this, "AccountNotUpdated");
} }

View File

@ -372,17 +372,23 @@ public class Match
m_sql.toString(), "hdr", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO) m_sql.toString(), "hdr", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO)
+ m_groupBy; + m_groupBy;
log.finest(sql); log.finest(sql);
Statement stmt = null;
ResultSet rs = null;
try try
{ {
Statement stmt = DB.createStatement(); stmt = DB.createStatement();
ResultSet rs = stmt.executeQuery(sql); rs = stmt.executeQuery(sql);
table.loadTable(rs); table.loadTable(rs);
stmt.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
finally
{
DB.close(rs,stmt);
rs = null;stmt = null;
}
} // tableLoad } // tableLoad
/** /**

View File

@ -831,10 +831,11 @@ public class DB_PostgreSQL implements AdempiereDatabase
public static void dumpLocks(Connection conn) public static void dumpLocks(Connection conn)
{ {
Statement stmt = null; Statement stmt = null;
ResultSet rs = null;
try { try {
String sql = "select pg_class.relname,pg_locks.* from pg_class,pg_locks where pg_class.relfilenode=pg_locks.relation order by 1"; String sql = "select pg_class.relname,pg_locks.* from pg_class,pg_locks where pg_class.relfilenode=pg_locks.relation order by 1";
stmt = conn.createStatement(); stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql); rs = stmt.executeQuery(sql);
int cnt = rs.getMetaData().getColumnCount(); int cnt = rs.getMetaData().getColumnCount();
System.out.println(); System.out.println();
while (rs.next()) while (rs.next())
@ -852,10 +853,8 @@ public class DB_PostgreSQL implements AdempiereDatabase
} catch (Exception e) { } catch (Exception e) {
} finally { } finally {
try{ DB.close(rs,stmt);
if (stmt != null) rs = null;stmt = null;
stmt.close();
} catch (Exception e) {}
} }
} }
@ -964,13 +963,24 @@ public class DB_PostgreSQL implements AdempiereDatabase
finally finally
{ {
if (rs != null) if (rs != null)
rs.getStatement().close(); DB.close(rs.getStatement());
DB.close(rs); DB.close(rs);
rs = null;
}
Statement timeoutStatement = null;
try
{
timeoutStatement = conn.createStatement();
String sql = "SET " + (autoCommit ? "SESSION" : "LOCAL") + " statement_timeout TO " + ( timeOut > 0 ? Integer.toString(timeOut * 1000) : " DEFAULT ");
timeoutStatement.execute(sql);
}
finally
{
DB.close(timeoutStatement);
timeoutStatement = null;
} }
Statement timeoutStatement = conn.createStatement();
String sql = "SET " + (autoCommit ? "SESSION" : "LOCAL") + " statement_timeout TO " + ( timeOut > 0 ? Integer.toString(timeOut * 1000) : " DEFAULT ");
timeoutStatement.execute(sql);
if (log.isLoggable(Level.FINEST)) if (log.isLoggable(Level.FINEST))
{ {
log.finest("Set statement timeout to " + timeOut); log.finest("Set statement timeout to " + timeOut);
@ -1035,6 +1045,7 @@ public class DB_PostgreSQL implements AdempiereDatabase
if(stmt!=null)setStatementTimeout(stmt.getConnection(), currentTimeout); if(stmt!=null)setStatementTimeout(stmt.getConnection(), currentTimeout);
} catch (SQLException e) {} } catch (SQLException e) {}
DB.close(rs, stmt); DB.close(rs, stmt);
rs = null;stmt = null;
} }
} }
return false; return false;

View File

@ -228,14 +228,9 @@ public class DBDataSource extends compiereDataSource
*/ */
public void close() public void close()
{ {
try DB.close(m_resultSet);
{ m_resultSet = null;
if(m_resultSet != null) DB.close(m_pstmt);
m_resultSet.close(); m_pstmt = null;
if(m_pstmt != null)
m_pstmt.close();
}
catch (Exception e){}
} }
} }