PreparedStatement clearParameters and setTimestamp
От | Akira Sato |
---|---|
Тема | PreparedStatement clearParameters and setTimestamp |
Дата | |
Msg-id | 44C5771E.4090103@oss.ntt.co.jp обсуждение исходный текст |
Ответы |
Re: PreparedStatement clearParameters and setTimestamp
|
Список | 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.
В списке pgsql-jdbc по дате отправления: