X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 656213A4AE9 for ; Sat, 13 Nov 2004 18:25:40 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31582-05 for ; Sat, 13 Nov 2004 18:25:35 +0000 (GMT) Received: from lucifer.oficina (unknown [200.68.121.201]) by svr1.postgresql.org (Postfix) with ESMTP id 566633A4AD7 for ; Sat, 13 Nov 2004 18:25:34 +0000 (GMT) Received: from localhost (localhost.akyasociados.com.ar [127.0.0.1]) by lucifer.oficina (8.13.1/8.12.10) with ESMTP id iADIPEwY052399; Sat, 13 Nov 2004 15:25:14 -0300 (ART) (envelope-from franco@akyasociados.com.ar) Received: from lucifer.oficina ([127.0.0.1]) by localhost (lucifer.oficina [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 50256-04; Sat, 13 Nov 2004 15:25:13 -0300 (ART) Received: from [192.168.1.168] (taz.oficina [192.168.1.168]) (authenticated bits=0) by lucifer.oficina (8.13.1/8.12.10) with ESMTP id iADIPADj052393; Sat, 13 Nov 2004 15:25:12 -0300 (ART) (envelope-from franco@akyasociados.com.ar) Message-ID: <41965186.4040300@akyasociados.com.ar> Date: Sat, 13 Nov 2004 15:25:10 -0300 From: Franco Bruno Borghesi User-Agent: Mozilla Thunderbird 0.9 (X11/20041113) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Kris Jurka Cc: pgsql-jdbc@postgresql.org Subject: Re: Question References: <41963B7A.8080900@akyasociados.com.ar> In-Reply-To: Content-Type: multipart/alternative; boundary="------------090901010708080402040209" X-Virus-Scanned: by amavisd-new at akyasociados.com.ar X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.5 tagged_above=0.0 required=5.0 tests=HTML_MESSAGE, HTML_TITLE_EMPTY X-Spam-Level: X-Archive-Number: 200411/110 X-Sequence-Number: 11532 This is a multi-part message in MIME format. --------------090901010708080402040209 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Thanks for the answer Kris. I've fixed a generic replace method that I had written, so it looks like this now (I've simplified it for the example): private void replateArgs(PreparedStatement stmt, Object[] values, int offset) { for (int i, count=values.length; iOn Sat, 13 Nov 2004, Franco Bruno Borghesi wrote: > > > >>Hi all. >> >>I've donwloaded pg80b1.308.jdbc3.jar from jdbc.postgresql.org and now my >>calls to PreparedStatement.setObject(int, Object) are failing, when they >>used to work with the previous driver version. >> >>The message I get is: "Cant infer the SQL type to use for an instance of >>{0}. Use setObject() with an explicit Types value to specify the type to >>use.". >> >>Calling setObject(int, Object, Types.xxxxx) works ok, but I need >>setObject(int, Object). I've tryied setObject(int, Character) and >>setObject(int, java.util.Date) and both fail with the same message. >>Haven't tested other cases. >> >> > >setObject(int, Object) has a limited number of types that it knows about >(and Character and java.util.Date aren't in them). Using String and >java.sql.Date will work but you probably don't want to do that. Supposing >we did add these two types to setObject's knowledge, what does >java.util.Date map to? With java.sql.Date/Time/Timestamp you know what >datatype you are really talking about. > >Kris Jurka > > > --------------090901010708080402040209 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Thanks for the answer Kris. I've fixed a generic replace method that I had written, so it looks like this now (I've simplified it for the example):

private void replateArgs(PreparedStatement stmt, Object[] values, int offset) {

    for (int i, count=values.length; i<count; i++) {

          //is it a Character?
        if (values[i] instanceof Character)
            pstmt.setObject(offset+i, values[i].toString());
        else {

             //is it a Date?
            if (values[i] instanceof java.util.Date)
                pstmt.setObject(offset+i, values[i], Types.TIMESTAMP); //all my tables have timestamp dates
            else //anything else seems to work
                pstmt.setObject(offset+i, values[i]); //any other thing
        }
    }
}

It works fine, except for NULL values. With the old driver, setObject(int, null) was ok, but I've seen that I should be using setNull(int, int) with the new version.

As you see, in my current code I have no way to know to which datatype the field maps to. So, is there any easy/generic way to set NULLs, no matter what datatype the field is?

Thanks again.

Kris Jurka wrote:
On Sat, 13 Nov 2004, Franco Bruno Borghesi wrote:

  
Hi all.

I've donwloaded pg80b1.308.jdbc3.jar from jdbc.postgresql.org and now my 
calls to PreparedStatement.setObject(int, Object) are failing, when they 
used to work with the previous driver version.

The message I get is: "Cant infer the SQL type to use for an instance of 
{0}. Use setObject() with an explicit Types value to specify the type to 
use.".

Calling setObject(int, Object, Types.xxxxx) works ok, but I need 
setObject(int, Object). I've tryied setObject(int, Character) and 
setObject(int, java.util.Date) and both fail with the same message. 
Haven't tested other cases.
    

setObject(int, Object) has a limited number of types that it knows about 
(and Character and java.util.Date aren't in them).  Using String and 
java.sql.Date will work but you probably don't want to do that.  Supposing 
we did add these two types to setObject's knowledge, what does 
java.util.Date map to?  With java.sql.Date/Time/Timestamp you know what 
datatype you are really talking about.

Kris Jurka

  

--------------090901010708080402040209--