Leverage PreparedStatement Pooling
You are guaranteed to see a performance
boost from prepared statements only when the underlying database
supports prepared statements and you repeatedly use the same
PreparedStatement instance. Your application will
probably receive a performance boost if you repeatedly use the same
prepared SQL statement. However, a performance boost is very unlikely
when you use a prepared statement only once.
To maximize the likelihood that you will see a performance boost in a
cross-platform environment, you need to find ways to reuse your
PreparedStatement instances. Unfortunately,
pooling prepared statements is not quite as straightforward as
pooling database connections. Because closing a connection closes any
associated statements, you cannot pool statements across connection
closures. The new JDBC 3.0 specification has stepped in to address
the problem by supporting prepared statement pooling inside the
specification.
The ability to use pooled prepared statements in JDBC 3.0 is hidden behind connection pooling. To take advantage of it, you must:
Use a JDBC 3.0 driver that supports pooled prepared statements.
Configure a data source for pooled connections that provide statement pooling.
Let’s review how connection pooling works. When an application requests a database connection, it receives a logical connection that at some point becomes associated with a physical database connection. Note that the application never has direct access to the physical database ...