Skip site navigation (1) Skip section navigation (2)

PreparedStatement clearParameters and setTimestamp

From: Akira Sato <sato(dot)akira(at)oss(dot)ntt(dot)co(dot)jp>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: PreparedStatement clearParameters and setTimestamp
Date: 2006-07-25 01:42:54
Message-ID: 44C5771E.4090103@oss.ntt.co.jp (view raw or flat)
Thread:
Lists: pgsql-jdbc
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.

Responses

pgsql-jdbc by date

Next:From: alanDate: 2006-07-25 10:42:36
Subject: Invalid column display size. Cannot be less than zero
Previous:From: Michael GuyverDate: 2006-07-23 12:04:43
Subject: Re: Trouble with CallableStatement

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group