pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Akira Sato <sato.akira@oss.ntt.co.jp>
To: pgsql-jdbc@postgresql.org
Subject: PreparedStatement clearParameters and setTimestamp
Date: Tue, 25 Jul 2006 10:42:54 +0900
Message-ID: <44C5771E.4090103@oss.ntt.co.jp> (raw)

Hi,

This reply is about the following threads.
http://archives.postgresql.org/pgsql-jdbc/2006-02/msg00156.php

With case of setTimestamp(), it seem to always do "Parse".
(setDate() and setTime() too)


JDBC driver   : 8.1-407
URL parameter : prepareThreshold=1&loglevel=2

sample code :

create table test(id int, tm timestamp);

int n = 10;
Timestamp tm = new Timestamp(System.currentTimeMillis());
PreparedStatement pst = conn.prepareStatement("INSERT INTO test(id, tm)
VALUES (?, ?)");
for(int i=0; i< n; i++){
    pst.clearParameters();
    pst.setInt(1, i);
    pst.setTimestamp(2, tm);
    pst.executeUpdate();
}
pst.close()

----


When we used poolPreparedStatements (common-dbcp), a similar problem
seems to occur. When we called close() of PreparedStatement, dbcp side
calls clearParameters().


JDBC driver     : 8.1-407
URL parameter   : prepareThreshold=1&loglevel=2
Jakarta commons : commons-dbcp-1.2.1
                  commons-pool-1.3
                  commons-collections-3.2

sample code :

import org.apache.commons.dbcp.BasicDataSource;
              :
String url =
"jdbc:postgresql://localhost/testdb?loglevel=2&prepareThreshold=1";
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName("org.postgresql.Driver");
ds.setUsername("user");
ds.setPassword("passwd");
ds.setUrl(url);
ds.setPoolPreparedStatements(true);

Connection conn = ds.getConnection();

int n = 10;
Timestamp tm = new Timestamp(System.currentTimeMillis());
for(int i=0; i< n; i++){psql tes
    PreparedStatement pst = conn.prepareStatement("INSERT INTO test(id,
tm) VALUES (?, ?)");
    pst.setInt(1, i);
    pst.setTimestamp(2, tm);
    pst.executeUpdate();
    pst.close()
}

----

best regards,

Akira.



view thread (3+ messages)  latest in thread

Message-ID: <44C5771E.4090103@oss.ntt.co.jp>
Permalink:  ../44C5771E.4090103@oss.ntt.co.jp/
Also on:    postgresql.org/message-id/44C5771E.4090103@oss.ntt.co.jp

 · 

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: sato.akira@oss.ntt.co.jp
  Subject: Re: PreparedStatement clearParameters and setTimestamp
  In-Reply-To: <44C5771E.4090103@oss.ntt.co.jp>
  References: <44C5771E.4090103@oss.ntt.co.jp>

* 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