From 94638ad16faa5aebaf5d0523314ac6eee7940e67 Mon Sep 17 00:00:00 2001 From: wenshao Date: Thu, 24 Nov 2016 00:30:11 +0800 Subject: [PATCH] bug fixed for pscache, if preparedStatement throw exception, removed from pscache. issue #1052 --- .../com/alibaba/druid/pool/DruidPooledConnection.java | 2 +- .../java/com/alibaba/druid/pool/DruidPooledStatement.java | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java b/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java index c7c591d7d7..8b0ab44974 100644 --- a/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java +++ b/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java @@ -164,7 +164,7 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql. } stmt.getPreparedStatementHolder().decrementInUseCount(); - if (stmt.isPooled() && holder.isPoolPreparedStatements()) { + if (stmt.isPooled() && holder.isPoolPreparedStatements() && stmt.exceptionCount == 0) { holder.getStatementPool().put(stmt.getPreparedStatementHolder()); stmt.clearResultSet(); diff --git a/src/main/java/com/alibaba/druid/pool/DruidPooledStatement.java b/src/main/java/com/alibaba/druid/pool/DruidPooledStatement.java index ec7bf594a3..f9fdc16e05 100644 --- a/src/main/java/com/alibaba/druid/pool/DruidPooledStatement.java +++ b/src/main/java/com/alibaba/druid/pool/DruidPooledStatement.java @@ -27,13 +27,14 @@ import java.util.List; */ public class DruidPooledStatement extends PoolableWrapper implements Statement { - private final static Log LOG = LogFactory.getLog(DruidPooledStatement.class); + private final static Log LOG = LogFactory.getLog(DruidPooledStatement.class); private final Statement stmt; protected DruidPooledConnection conn; protected List resultSetTrace; - protected boolean closed = false; - protected int fetchRowPeak = -1; + protected boolean closed = false; + protected int fetchRowPeak = -1; + protected int exceptionCount = 0; public DruidPooledStatement(DruidPooledConnection conn, Statement stmt){ super(stmt); @@ -60,6 +61,7 @@ public class DruidPooledStatement extends PoolableWrapper implements Statement { } protected SQLException checkException(Throwable error) throws SQLException { + exceptionCount++; return conn.handleException(error); }