pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Burdairon <tburdairon@entelience.com>
To: pgsql-jdbc@postgresql.org
Subject: PreparedStatement clearParameters
Date: Mon, 20 Feb 2006 13:58:44 +0100
Message-ID: <FD2E9949-0E9B-4C0D-92E7-2AB587DC319B@entelience.com> (raw)

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





view thread (4+ messages)  latest in thread

Message-ID: <FD2E9949-0E9B-4C0D-92E7-2AB587DC319B@entelience.com>
Permalink:  ../FD2E9949-0E9B-4C0D-92E7-2AB587DC319B@entelience.com/
Also on:    postgresql.org/message-id/FD2E9949-0E9B-4C0D-92E7-2AB587DC319B@entelience.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: tburdairon@entelience.com
  Subject: Re: PreparedStatement clearParameters
  In-Reply-To: <FD2E9949-0E9B-4C0D-92E7-2AB587DC319B@entelience.com>
  References: <FD2E9949-0E9B-4C0D-92E7-2AB587DC319B@entelience.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox