--- jon gold <[EMAIL PROTECTED]> wrote:
> i notice that QueryRunner.query always prepares a statement -- even if
> there are no replacement parameters. why is this?
You don't need replacement parameters to benefit from caching and reusing
PreparedStatement instances.
>
> the reason i ask is that it leads to undue bloat on a statement pool
> when used in conjunction with a connection from a connection pool. in
> our case, we eventually get OutOfMemoryErrors.
What pool implementation are you using? It seems like you could configure
the pool to not use up all your memory.
> i've subclassed
> QueryRunner in my application anyway, so it's not a big deal for me to
> handle this locally, but it seems like it would be nice to replace the
> block:
>
> PreparedStatement stmt = null;
> ResultSet rs = null;
> Object result = null;
>
> try {
> stmt = this.prepareStatement(conn, sql);
> this.fillStatement(stmt, params);
>
> rs = this.wrap(stmt.executeQuery());
> ...
>
> with
>
> Statement stmt = null;
> ResultSet rs = null;
> Object result = null;
>
> try {
> if ( params != null ) {
> stmt = this.prepareStatement(conn, sql);
> this.fillStatement((PreparedStatement)stmt, params);
> rs = this.wrap(stmt.executeQuery());
> }
> else {
> stmt = conn.createStatement();
> rs = this.wrap(stmt.executeQuery(sql);
> }
>
> ...
>
> that way if i want to prepare and keep a no-param statement, i pass in a
>
> non-null but empty Object[] for params. if i want to say "just run this
> statement but throw it away," then i pass in null (ie, just call
> QueryRunner.query( sql, rsh ) as is.
>
While that is certainly doable it's not at all clear to the user of the
API. They have to remember that null indicates a special behavior which
is almost always confusing and error prone.
I really don't see this as a DbUtils problem. QueryRunner is doing its
best to provide good performance by using PreparedStatements. A
connection/statement pool should allow you to configure its maximum size
so it doesn't use all your memory. If it doesn't, subclassing QueryRunner
for these special cases is the best solution.
David
>
> jon
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]