Re: PreparedStatement clearParameters

From: Kris Jurka <books(at)ejurka(dot)com>
To: Thomas Burdairon <tburdairon(at)entelience(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: PreparedStatement clearParameters
Date: 2006-02-20 17:58:04
Message-ID: Pine.BSO.4.63.0602201252290.23155@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Mon, 20 Feb 2006, Thomas Burdairon wrote:

> I've seen a strange comportment of implementation of PreparedStatement
> and especially the clearParameters method. The normal functionnement of
> this is that if I create a PreparedStatement, the query is sent once to
> the server, and then only parameters are sent to the server.
> clearParameters erase parameters already set in the PreparedStatement
> object.
>
> But, it seems the clearParameters method remove us all the benefit of
> prepare statements, because the query is sent again on each
> executeQuery/executeUpdate call. But without using clearParameters, the
> comportment is correct.

Yes, this is a problem. The coding of clearParameters clears the type
information associated with the PreparedStatement as well as the bind
values. This causes the query to get reprepared as it thinks the types
have changed. This code is necessary because the statement must
be replanned when something like this happens:

ps.setInt(1, 1);
ps.execute();
ps.setLong(1, 1);
ps.execute();

I suspect that just not clearing the type information will fix this, but
I'll need to test that a little. Thanks for the report.

Kris Jurka

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Warren Murray 2006-02-20 21:10:55 PostgreSQL and Struts Tutorial
Previous Message Kris Jurka 2006-02-20 17:42:16 Re: setString and timestamps