The maxStatements property, available on the UDBConnectionPoolDataSource interface, allows for statement pooling within the connection pool. Statement pooling only has an effect on PreparedStatements and CallableStatements. Statement objects are not pooled.
The implementation of statement pooling is similar to that of connection pooling. When the application calls Connection.prepareStatement("select * from tablex"), the pooling module checks if the Statement object has already been prepared under the connection. If it has, a logical PreparedStatement object is handed to you instead of the physical object. When you call close, the Connection object is returned to the pool, the logical Connection object is thrown away, and the Statement object can be reused.
The maxStatements property allows the DataSource to specify how many statements can be pooled under a connection. A value of 0 indicates that statement pooling should not be used. When the statement pool is full, a least recently used algorithm is applied to determine which statement is to be thrown out.
Example: Test the performance of two DataSources tests one DataSource that uses connection pooling only and the other DataSource that uses statement and connection pooling.
The following example is output from running this program locally during development.
Deploying statement pooling data source Start timing the connection pooling only version... Time spent: 26312
Starting timing the statement pooling version... Time spent: 2292 Java™ program completed