i notice that QueryRunner.query always prepares a statement -- even if there are no replacement parameters. why is this?

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. 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.


jon

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to