Does BoneCP (or any other pool) close connection's statements when connection is returned to pool?

StackOverflow https://stackoverflow.com/questions/4348814

  •  30-09-2019
  •  | 
  •  

Pergunta

Does BoneCP (or any other pool) close connection's statements when connection is returned to pool? As I understand, it does not call actual connection's close method, so there is no automatic statement closing. So, does it close statements in any other way or do I need to close them manually?

Foi útil?

Solução

The JDBC spec is very unclear on what should happen under normal connection close so, irrespective of the pool you use, you should always make sure to close off the statements manually. Consider what would happen to your application if you opt to switch to a different pool in the future that does not do what you expect it to do for you.

As regards BoneCP, the answer is no, it will not close off your statements for you though it can be configured to close off your connections if you forget. This is for performance reasons since some JDBC drivers will close off any still active statements internally if you close off the connection.

However, BoneCP will close off any cached statements if you have statements caching enabled.

EDIT: As of v0.8.0, support has been added to close off unclosed statements (+ print out stack trace of location where statement was opened if you want).

Outras dicas

BoneCP (0.8.0 -RC3), there are 2 possible results,

close off with some configuration for non-cached statement only

non-close off no matter how you configure it for cached statement even you invoke the statement.close() explicitly.

There is a StatementCache class to cache the preparedStatement & callableStatement. The default is disabled. You need call BoneCPConfig.setStatementsCacheSize() with the >0 parameter to enable it. After enable the cache,

1 BoneCP.Statement.Close() will bypass the underlying statement close if it is cached.

  public void close() throws SQLException {
      this.connectionHandle.untrackStatement(this);
  this.logicallyClosed.set(true);
  if (this.logStatementsEnabled){
        this.logParams.clear();
        this.batchSQL = new StringBuilder();
      }

      if (this.cache == null || !this.inCache){ // no cache = throw it away right now
           this.internalStatement.close();
  }
}

2 BoneCP.Connection.close() Will just simply clear the cache through the function "clearStatementCaches()"

The good news is MYSQL JDBC driver, Connector/J, will close all the opened statements when you close the connection through the function "closeAllOpenStatements()"

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top