Re: setObject(int,Object) can not convert Java String object to backend's Integer type

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: Chen Huajun <chenhj(at)cn(dot)fujitsu(dot)com>
Cc: List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: setObject(int,Object) can not convert Java String object to backend's Integer type
Date: 2013-01-08 11:15:24
Message-ID: CADK3HHL_m1fQpoxoDggxuGqmhxPY2Rvy-O1V6o4fT9FJ0oS7sg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Chen,

This link
http://docs.oracle.com/javase/1.3/docs/guide/jdbc/getstart/mapping.htmlshould
clarify things. The mapping is actually String to char, varchar, or
longvarchar.

Dave

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On Tue, Jan 8, 2013 at 6:04 AM, Chen Huajun <chenhj(at)cn(dot)fujitsu(dot)com> wrote:

> Hi,
>
> According to JDBC Specification Java String object could be converted to
> backend's Integer type by setObject().
> But in PostgreSQL JDBC, it's not true. It seems to be a bug.
>
> Sample:
> PreparedStatement stmt = con.prepareStatement("select 1::int = ?");
> stmt.setObject(1, "2");
> ResultSet rs = stmt.executeQuery();//raises an error here!
>
> *)but the following is OK
> stmt.setObject(1, "2",Types.INTEGER);
> stmt.setObject(1, "2",Types.OTHER);
>
>
> Internally stmt.setObject(1, "2") binds "2" as varchar ,
> if it binds "2" as unspecified type,the result will be OK.
>
>
>
> Regards,
> Chen Huajun
>
>
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Chen Huajun 2013-01-08 11:59:55 Re: setObject(int,Object) can not convert Java String object to backend's Integer type
Previous Message Chen Huajun 2013-01-08 11:04:34 setObject(int, Object) can not convert Java String object to backend's Integer type