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