From ccf611bca0dbdb4e2d9f24d0bb9b68e3251ae0f2 Mon Sep 17 00:00:00 2001 From: FuZhenn Date: Wed, 9 Mar 2016 16:01:37 +0800 Subject: [PATCH] Add exception handling when closing statement --- .../alibaba/druid/pool/DruidPooledConnection.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java b/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java index b208ae32be..cbe3ae58ea 100644 --- a/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java +++ b/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java @@ -174,8 +174,16 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql. stmt.setClosed(true); // soft set close } else { - stmt.closeInternal(); - holder.getDataSource().incrementClosedPreparedStatementCount(); + try { + //Connection behind the statement may be in invalid state, which will throw a SQLException. + //In this case, the exception is desired to be properly handled to remove the unusable connection from the pool. + stmt.closeInternal(); + } catch (SQLException ex) { + this.handleException(ex); + throw ex; + } finally { + holder.getDataSource().incrementClosedPreparedStatementCount(); + } } }