Add exception handling when closing statement

This commit is contained in:
FuZhenn
2016-03-09 16:01:37 +08:00
parent 94a3a65c3d
commit ccf611bca0
@@ -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();
}
}
}