DB2 Version 9.7 for Linux, UNIX, and Windows

IBM Data Server Driver for JDBC and SQLJ statement caching

The IBM® Data Server Driver for JDBC and SQLJ can use an internal statement cache to improve the performance of Java™ applications by caching and pooling prepared statements.

Internal statement caching is available for connections that use IBM Data Server Driver for JDBC and SQLJ type 4 connectivity, or for connections that use IBM Data Server Driver for JDBC and SQLJ type 2 connectivity on DB2® for z/OS®.

You enable internal statement caching in any of the following ways:

When internal statement caching is enabled, the IBM Data Server Driver for JDBC and SQLJ can cache PreparedStatement objects, CallableStatement objects, and JDBC resources that are used by SQLJ statements when those objects or resources are logically closed. When you explicitly or implicitly invoke the close method on a statement, you logically close the statement.

Reuse of a previously cached statement is transparent to applications. The statement cache exists for the life of an open connection. When the connection is closed, the driver deletes the statement cache and closes all pooled statements.

A logically open statement becomes ineligible for caching under either of the following circumstances:

When the IBM Data Server Driver for JDBC and SQLJ attempts to cache a statement, and the internal statement cache is full, the driver purges the least recently used cached statement, and inserts the new statement.

The internal statement cache is purged under the following conditions:

In a Java program, you can test whether the internal statement cache is enabled by issuing the DatabaseMetaData.supportsStatementPooling method. The method returns true if the internal statement cache is enabled.

The IBM Data Server Driver for JDBC and SQLJ does not check whether the definitions of target objects of statements in the internal statement cache have changed. If you execute SQL data definition language statements in an application, you need to disable internal statement caching for that application.

The internal statement cache requires extra memory. If memory becomes constrained, you can increase the JVM size, or decrease the value of maxStatements.