diff --git a/dbPort/src/org/compiere/util/CCachedRowSet.java b/dbPort/src/org/compiere/util/CCachedRowSet.java index 10aebd5c64..844c8beaab 100644 --- a/dbPort/src/org/compiere/util/CCachedRowSet.java +++ b/dbPort/src/org/compiere/util/CCachedRowSet.java @@ -93,6 +93,7 @@ public class CCachedRowSet extends CachedRowSetImpl implements CachedRowSet ResultSet rs = stmt.executeQuery(sql); OracleCachedRowSet crs = new OracleCachedRowSet(); crs.populate(rs); + rs.close(); stmt.close(); return crs; } diff --git a/dbPort/src/org/compiere/util/CPreparedStatement.java b/dbPort/src/org/compiere/util/CPreparedStatement.java index 2f6918ffec..5ceb0202cc 100644 --- a/dbPort/src/org/compiere/util/CPreparedStatement.java +++ b/dbPort/src/org/compiere/util/CPreparedStatement.java @@ -134,9 +134,9 @@ public class CPreparedStatement extends CStatement implements PreparedStatement } // Try locally log.warning("Execute locally"); - PreparedStatement pstmt = local_getPreparedStatement (false, null); // shared connection + p_stmt = local_getPreparedStatement (false, null); // shared connection p_vo.clearParameters(); // re-use of result set - ResultSet rs = pstmt.executeQuery(); + ResultSet rs = ((PreparedStatement)p_stmt).executeQuery(); return rs; } // executeQuery @@ -191,9 +191,9 @@ public class CPreparedStatement extends CStatement implements PreparedStatement } // Try locally log.warning("execute locally"); - PreparedStatement pstmt = local_getPreparedStatement (false, null); // shared connection + p_stmt = local_getPreparedStatement (false, null); // shared connection p_vo.clearParameters(); // re-use of result set - return pstmt.executeUpdate(); + return ((PreparedStatement)p_stmt).executeUpdate(); } // executeUpdate /** @@ -908,6 +908,7 @@ public class CPreparedStatement extends CStatement implements PreparedStatement // ResultSet rs = pstmt.executeQuery(); rowSet = CCachedRowSet.getRowSet(rs); + rs.close(); pstmt.close(); pstmt = null; conn.close(); @@ -1023,6 +1024,8 @@ public class CPreparedStatement extends CStatement implements PreparedStatement rowSet = CCachedRowSet.getRowSet(rs); pstmt.close(); pstmt = null; + rs.close(); + rs = null; } catch (Exception ex) { @@ -1050,15 +1053,15 @@ public class CPreparedStatement extends CStatement implements PreparedStatement public int remote_executeUpdate() { log.finest("Update"); + PreparedStatement pstmt = null; try { AdempiereDatabase db = CConnection.get().getDatabase(); if (db == null) throw new NullPointerException("Remote - No Database"); // - PreparedStatement pstmt = local_getPreparedStatement (false, p_vo.getTrxName()); + pstmt = local_getPreparedStatement (false, p_vo.getTrxName()); int result = pstmt.executeUpdate(); - pstmt.close(); // return result; } @@ -1067,6 +1070,14 @@ public class CPreparedStatement extends CStatement implements PreparedStatement log.log(Level.SEVERE, p_vo.toString(), ex); throw new RuntimeException (ex); } + finally { + if (pstmt != null) { + try { + pstmt.close(); + } catch (SQLException e) {} + pstmt = null; + } + } } // remote_executeUpdate //remove this commnet if you want use JAVA 6 diff --git a/dbPort/src/org/compiere/util/CStatement.java b/dbPort/src/org/compiere/util/CStatement.java index 1b4fa0a63f..6e12928df8 100644 --- a/dbPort/src/org/compiere/util/CStatement.java +++ b/dbPort/src/org/compiere/util/CStatement.java @@ -145,8 +145,8 @@ public class CStatement implements Statement } // Try locally log.warning("execute locally"); - Statement stmt = local_getStatement (false, null); // shared connection - return stmt.executeQuery(p_vo.getSql()); + p_stmt = local_getStatement (false, null); // shared connection + return p_stmt.executeQuery(p_vo.getSql()); } // executeQuery @@ -191,8 +191,8 @@ public class CStatement implements Statement } // Try locally log.warning("execute locally"); - Statement pstmt = local_getStatement (false, null); // shared connection - return pstmt.executeUpdate(p_vo.getSql()); + p_stmt = local_getStatement (false, null); // shared connection + return p_stmt.executeUpdate(p_vo.getSql()); } // executeUpdate /** @@ -717,15 +717,15 @@ public class CStatement implements Statement public int remote_executeUpdate() { log.finest(""); + Statement pstmt = null; try { AdempiereDatabase db = CConnection.get().getDatabase(); if (db == null) throw new NullPointerException("Remote - No Database"); // - Statement pstmt = local_getStatement (false, p_vo.getTrxName()); + pstmt = local_getStatement (false, p_vo.getTrxName()); int result = pstmt.executeUpdate(p_vo.getSql()); - pstmt.close(); // return result; } @@ -733,6 +733,16 @@ public class CStatement implements Statement { log.log(Level.SEVERE, p_vo.toString(), ex); throw new RuntimeException (ex); + } + finally { + if (pstmt != null) + { + try + { + pstmt.close(); + } catch (SQLException e){} + pstmt = null; + } } } // remote_executeUpdate @@ -884,6 +894,7 @@ public class CStatement implements Statement // ResultSet rs = pstmt.executeQuery(); rowSet = CCachedRowSet.getRowSet(rs); + rs.close(); pstmt.close(); pstmt = null; }