Subject Re: [Firebird-Java] Re: Can I cache prepared statements in my own pool?
Author Roman Rokytskyy
> Roman, you mean the modern C.P.D.S. does implement this? Damn sorry,
> then I should upgrade! :)

I mean that our CPDS implemented that from the very beginning and DS since
new pooling framework, though I do not know about the others. :) It is
definitely part of JayBird 1.5.x and will be supported in JayBird 2.0 too.
You just have to specify the maxStatements parameter (though, if I remember
correctly, it is 10 by default)

It is not available on the JCA level when the connection is obtained via
FBManagedConnectionFactory, since statement pooling is part of the pooling
framework and not the JCA code. JCA container might pool them, but most
likely not.

CallableStatements are not pooled, if anybody is willing to contribute the
implementation (quite easy, very similar to PreparedStatement), you're
welcome.

The usage pattern should be something like this:

Connection connection = ds.getConnection();
try {
PreparedStatement ps = connection.prepareStatement(sql);
try {
// do something
} finally {
ps.close();
}
} finally {
connection.close();
}

Both operations are cheap when the cache is used and the try/finally
guarantees that statement/connection are returned to the pool.

Roman