From 1d7bc65b3d8f3d5dbaca7e45a8b1b9d78ed2a104 Mon Sep 17 00:00:00 2001 From: DigitalSonic Date: Fri, 24 Feb 2017 00:05:34 +0800 Subject: [PATCH] remove the statement from pool while it threw an exception MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While the pooled PreparedStatement threw an exception, remove it from the pool, and then close it. The commit 94638ad didn’t fix issue #1498 . Try this one. --- .../com/alibaba/druid/pool/DruidPooledConnection.java | 6 ++++++ .../com/alibaba/druid/pool/PreparedStatementPool.java | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java b/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java index 2f95d12309..c4761d7f92 100644 --- a/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java +++ b/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java @@ -173,6 +173,12 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql. stmt.getPreparedStatementHolder().setFetchRowPeak(stmt.getFetchRowPeak()); stmt.setClosed(true); // soft set close + } else if (stmt.isPooled() && holder.isPoolPreparedStatements()) { + // the PreparedStatement threw an exception + stmt.clearResultSet(); + holder.removeTrace(stmt); + + holder.getStatementPool().remove(stmt.getPreparedStatementHolder()); } else { try { //Connection behind the statement may be in invalid state, which will throw a SQLException. diff --git a/src/main/java/com/alibaba/druid/pool/PreparedStatementPool.java b/src/main/java/com/alibaba/druid/pool/PreparedStatementPool.java index d6f64ebc18..03d556fab4 100644 --- a/src/main/java/com/alibaba/druid/pool/PreparedStatementPool.java +++ b/src/main/java/com/alibaba/druid/pool/PreparedStatementPool.java @@ -72,6 +72,14 @@ public class PreparedStatementPool { return holder; } + public void remove(PreparedStatementHolder stmtHolder) throws SQLException { + if (stmtHolder == null) { + return; + } + map.remove(stmtHolder.key, stmtHolder); + closeRemovedStatement(stmtHolder); + } + public void put(PreparedStatementHolder stmtHolder) throws SQLException { PreparedStatement stmt = stmtHolder.statement;