The statement pool of JDBC allows applications to reuse PreparedStatement objects in the same way as using Connection objects.
Multiple logical connections can reuse PreparedStatement objects without configuration.
Use pooled statements
An application can call the isPoolable method from the Statement API to check whether the data source supports statement pooling. If true is returned, the application learns that PreparedStatement objects are under preparation. The application can also call the setPoolable method from the Statement API to request statements to be or not to be merged.
The application can reuse pooled statements without configuration. That is, regardless of whether the PreparedStatement objects are pooled, the application code remains the same. If the application disables thePreparedStatement objects, you can call the Connection.prepareStatement method to reuse them.
Disable pooled statements
An application can disable pooled statements and non-pooled statements in the same way. If a statement is disabled, it is no longer available for the application, regardless of whether it is pooled. An error will occur if you attempt to reuse the statement. The only difference between disabling a pooled statement and a non-pooled statement lies in that the application cannot directly disable a physical statement that is being pooled. It can only be disabled by the pool manager. The PooledConnection.closeAll method disables all available statements on a given physical connection to release the resources associated with the statements.
You can disable a pooled statement by using the following methods:
closeThis
java.sql.Statementmethod can be called by an application. If the statement is being pooled, this method disables the logical statement used by the application, but not the physical statement that is being pooled.
closeThis
java.sql.Connectionmethod can be called by an application. The behavior of this method varies depending on whether the connection using the statement is pooled.
Non-pooled connection
This method disables the physical connection and all statements created by the connection. This is necessary because the garbage collection mechanism cannot detect when externally managed resources can be released.
Pooled connection
This method disables the logical connection and the logical statement it returns, but enables the underlying
PooledConnectionobject and all associated cache statements.
PooledConnection.closeAllThe connection pool manager calls this method to disable all physical statements that are being pooled for the
PooledConnectionobject.