Hi,
On 8/21/07, Thomas Mueller <[EMAIL PROTECTED]> wrote:
> Reusing prepared statements is harder with pooled connections. In JDK
> 1.6, thanks to javax.sql.StatementEventListener, they can if the
> connection pool manager supports it. In JDK 1.4 and 1.5, I am not sure
> what / when connection pool managers can reuse them.
If we did use a pooled DataSource, then I'd preferably drop all the
long-lived prepared statements that are currently kept as member
variables by the database persistence managers. Individual persistence
methods would become something like this:
void foo() throws ... {
Connection connnection = datasource.getConnection();
try {
PreparedStatement ps = connection.prepareStatement(...);
try {
// use the prepared statement
} finally {
ps.close();
}
} finally {
connection.close();
}
}
Any reasonable connection pool will pool also the prepared statements,
so the above code would normally only require an extra hash lookup and
some bookkeeping overhead.
BR,
Jukka Zitting