remove the statement from pool while it threw an exception

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.
This commit is contained in:
DigitalSonic
2017-02-24 00:05:34 +08:00
parent 112819fe4e
commit 1d7bc65b3d
2 changed files with 14 additions and 0 deletions
@@ -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.
@@ -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;