From 42d32cc8f197508dea46a593e7a6d3b7e60867c4 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Tue, 12 Feb 2008 04:55:37 +0000 Subject: [PATCH] [ 1874419 ] JDBC Statement not close in a finally block --- base/src/org/compiere/model/PO_LOB.java | 59 +++++++++++-------------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/base/src/org/compiere/model/PO_LOB.java b/base/src/org/compiere/model/PO_LOB.java index ab4d177f62..77d0756ecc 100644 --- a/base/src/org/compiere/model/PO_LOB.java +++ b/base/src/org/compiere/model/PO_LOB.java @@ -21,7 +21,6 @@ import java.rmi.*; import java.sql.*; import java.util.logging.*; -import org.compiere.Adempiere; import org.compiere.db.*; import org.compiere.interfaces.*; import org.compiere.util.*; @@ -121,16 +120,16 @@ public class PO_LOB implements Serializable { // See ServerBean success = server.updateLOB (sql.toString(), m_displayType, m_value, SecurityToken.getInstance()); if (CLogMgt.isLevelFinest()) - log.fine("server => " + success); - if (success) - return true; + log.fine("server.updateLOB => " + success); + return success; } - log.log(Level.SEVERE, "AppsServer not found"); + log.log(Level.SEVERE, "AppsServer not found"); } catch (RemoteException ex) { log.log(Level.SEVERE, "AppsServer error", ex); } + return false; } log.fine("[" + trxName + "] - Local - " + m_value); @@ -162,27 +161,18 @@ public class PO_LOB implements Serializable int no = pstmt.executeUpdate(); if (no != 1) { - log.fine("[" + trxName + "] - Not updated #" + no + " - " + sql); + log.warning("[" + trxName + "] - Not updated #" + no + " - " + sql); success = false; } - // - pstmt.close(); - pstmt = null; } - catch (Exception e) + catch (Throwable e) { log.log(Level.SEVERE, "[" + trxName + "] - " + sql, e); success = false; } - // Close Statement - try - { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(pstmt); pstmt = null; } @@ -198,15 +188,21 @@ public class PO_LOB implements Serializable { try { - con.commit(); - con.close(); - con = null; + con.commit(); } catch (Exception e) { log.log(Level.SEVERE, "[" + trxName + "] - commit " , e); success = false; } + finally + { + try { + con.close(); + } catch (SQLException e) { + } + con = null; + } } } // Error - roll back @@ -224,27 +220,22 @@ public class PO_LOB implements Serializable try { con.rollback(); - con.close(); - con = null; } catch (Exception ee) { log.log(Level.SEVERE, "[" + trxName + "] - rollback" , ee); } + finally + { + try { + con.close(); + } catch (SQLException e) { + } + con = null; + } } } - // Clean Connection - try - { - if (con != null) - con.close(); - con = null; - } - catch (Exception e) - { - con = null; - } return success; } // save