Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 394229F99A6 for ; Fri, 9 Nov 2007 12:48:30 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 16061-01 for ; Fri, 9 Nov 2007 12:48:22 -0400 (AST) Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.224]) by postgresql.org (Postfix) with ESMTP id 0A9F89F96B6 for ; Fri, 9 Nov 2007 12:48:11 -0400 (AST) Received: by nz-out-0506.google.com with SMTP id l8so490990nzf for ; Fri, 09 Nov 2007 08:48:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; bh=yoGXmp7gpleg9FtG2Js293BJmHA5U5W2rH1H2ad0muc=; b=Yili90Fqbwxu4qCMcgkCBGoy/Mwb/p2QpgXh/AphVzlsM7ugX4Wvhw5mJuqs7f+f3ted5sKyPqJTYfYy4njKGDc/E8dTo3ur2d+AHldNz3ETOD9bumhz2MnleJMRSqTwYiG2qKZeGiQzTNHF9L4invDGau8NGfhqUP02blTtzgQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=kpeIPUe/9dbiX+z2iXhS/ejek68J/H2pYVTNfJIKemiMtbWOZLuBXr7o1RfjN6A9sddCo7vBcbnNvhHYQ+DASz3JCO7JRuwQcIRtifPtB/f+essg519QePG3/dxHaYq+RKM9TORxHis9OFFK5y5dNAQaOUgLP59imSi+Ll1bocw= Received: by 10.142.191.2 with SMTP id o2mr757802wff.1194626888964; Fri, 09 Nov 2007 08:48:08 -0800 (PST) Received: by 10.142.203.5 with HTTP; Fri, 9 Nov 2007 08:48:08 -0800 (PST) Message-ID: <3a69fa320711090848n7d51dc57td54f23e0754679cb@mail.gmail.com> Date: Sat, 10 Nov 2007 01:48:08 +0900 From: "=?ISO-2022-JP?B?GyRCMSs/OTY/QkBPOhsoQg==?=" To: pgsql-jdbc@postgresql.org Subject: Bug? report : PreparedStatement.setObject(java.util.Date) don't work MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_37583_32851690.1194626888956" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/41 X-Sequence-Number: 17796 ------=_Part_37583_32851690.1194626888956 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello. I've faced problem similar to http://archives.postgresql.org/pgsql-jdbc/2007-06/msg00070.php Source: ------------------------------------------------------------------------- package test; import java.sql.*; import java.util.*; public class TestDate{ public static void main(String[] ags){ try{ Class.forName("org.postgresql.Driver"); Connection con = DriverManager.getConnection( "jdbc:postgresql:dbname", "user", "pass"); PreparedStatement stmt = con.prepareStatement("select * from table_name where column_name = ?"); stmt.setObject(1, new java.util.Date()); ResultSet rs = stmt.executeQuery(); while(rs.next()){ System.out.println( rs.getDate(1) ); } }catch(Exception e){ e.printStackTrace(); } } } ------------------------------------------------------------------------- Message: ------------------------------------------------------------------------- org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of java.util.Date. Use setObject() with an explicit Types value to specify the type to use. at org.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statement.java:1737) at test.TestDate.main(TestDate.java:16) ------------------------------------------------------------------------- It seemed org.postgresql.jdbc2.AbstractJdbc2Statement#setObject(int, Object) can't map java.util.Date to java.sql.Types#DATE. So I modified AbstractJdbc2Statement.java to accept java.util.Date,then it worked. Modification: ------------------------------------------------------------------------- diff postgresql-jdbc-8.2-506.src/org/postgresql/jdbc2/AbstractJdbc2Statement.java postgresql-jdbc-8.2-506.src_mod/org/postgresql/jdbc2/AbstractJdbc2Statement.java 1717a1718,1719 > else if (x instanceof java.util.Date) > setDate(parameterIndex, new java.sql.Date(((java.util.Date)x).getTime())); ------------------------------------------------------------------------- Is this good solution? Please advice. Gotaro AMENOMORi ------=_Part_37583_32851690.1194626888956 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
Hello.

I've faced problem similar to http://archives.postgresql.org/pgsql-jdbc/2007-06/msg00070.php

Source:
-------------------------------------------------------------------------
package test;

import java.sql.*;
import java.util.*;

public class TestDate{
public static void main(String[] ags){
try{
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection(
"jdbc:postgresql:dbname",
"user",
"pass");

PreparedStatement stmt = con.prepareStatement("select * from table_name where column_name = ?");
stmt.setObject(1, new java.util.Date());
ResultSet rs = stmt.executeQuery();

while(rs.next ()){
System.out.println( rs.getDate(1) );
}
}catch(Exception e){
e.printStackTrace();
}
}
}

-------------------------------------------------------------------------

Message:
-------------------------------------------------------------------------
org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of java.util.Date. Use setObject() with an explicit Types value to specify the type to use.
at org.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statement.java:1737)
at test.TestDate.main(TestDate.java:16)
-------------------------------------------------------------------------

It seemed org.postgresql.jdbc2.AbstractJdbc2Statement#setObject(int, Object) can't
map java.util.Date to java.sql.Types#DATE.
So I modified AbstractJdbc2Statement.java to accept java.util.Date,then it worked.

Modification:
-------------------------------------------------------------------------
diff postgresql-jdbc-8.2-506.src/org/postgresql/jdbc2/AbstractJdbc2Statement.java postgresql-jdbc-8.2-506.src_mod/org/postgresql/jdbc2/AbstractJdbc2Statement.java
1717a1718,1719
> else if (x instanceof java.util.Date)
> setDate(parameterIndex, new java.sql.Date(((java.util.Date)x).getTime()));
-------------------------------------------------------------------------

Is this good solution?
Please advice.

Gotaro AMENOMORi
------=_Part_37583_32851690.1194626888956--