PreparedStatement clearParameters

From: Thomas Burdairon <tburdairon(at)entelience(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: PreparedStatement clearParameters
Date: 2006-02-20 12:58:44
Message-ID: FD2E9949-0E9B-4C0D-92E7-2AB587DC319B@entelience.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hello all
First, i'm not sure about if this is the right place to post it, but
didn't see any bugtracker on the web site.
I don't know if it's a known bug, i didn't found any reference to it
on the Todo page, or in mailing list archives
Then, i don't even know if it's a bug, maybe it's a feature (?)

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

Tested on
Postgresql : 8.1 (MacOsX)
JDBC driver : release 404

sample code :

create table test(id int, desc text);

int n=1000;
PreparedStatement pst = db.prepareStatement("INSERT INTO test(id,
desc) VALUES (?, ?)");
for(int i=0; i< n; i++){
pst.setInt(1, i);
pst.setString(2, "haha");
pst.executeUpdate();
}

//opposite to

PreparedStatement pst2 = db.prepareStatement("INSERT INTO test(id,
desc) VALUES (?, ?)");
for(int i=0; i< n; i++){
pst.clearParameters();
pst.setInt(1, i);
pst.setString(2, "hoho");
pst.executeUpdate();
}

To check the communication between jdbc driver and postgresql server,
you can use this simple shell script :
sudo tcpdump -i lo0 -A -s 65535 tcp port 5432 (assuming the
postgresql port is 5432)

Thomas

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message David Goodenough 2006-02-20 14:31:55 Re: setString and timestamps
Previous Message Roman Chervotkin 2006-02-20 12:41:19 Re: Sun Java Studio Creator 2