PreparedStatement clearParameters - Mailing list pgsql-jdbc

From Thomas Burdairon
Subject PreparedStatement clearParameters
Date
Msg-id FD2E9949-0E9B-4C0D-92E7-2AB587DC319B@entelience.com
Whole thread Raw
Responses Re: PreparedStatement clearParameters  (Kris Jurka <books@ejurka.com>)
List 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



pgsql-jdbc by date:

Previous
From: "Roman Chervotkin"
Date:
Subject: Re: Sun Java Studio Creator 2
Next
From: David Goodenough
Date:
Subject: Re: setString and timestamps