pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedsetObject(int, Object) can not convert Java String object to backend's Integer type
3+ messages / 2 participants
[nested] [flat]
* setObject(int, Object) can not convert Java String object to backend's Integer type
@ 2013-01-08 11:04 Chen Huajun <chenhj@cn.fujitsu.com>
0 siblings, 1 reply; 3+ messages in thread
From: Chen Huajun @ 2013-01-08 11:04 UTC (permalink / raw)
To: pgsql-jdbc
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@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: setObject(int,Object) can not convert Java String object to backend's Integer type
@ 2013-01-08 11:15 Dave Cramer <pg@fastcrypt.com>
parent: Chen Huajun <chenhj@cn.fujitsu.com>
0 siblings, 1 reply; 3+ messages in thread
From: Dave Cramer @ 2013-01-08 11:15 UTC (permalink / raw)
To: Chen Huajun <chenhj@cn.fujitsu.com>; +Cc: 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@cn.fujitsu.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@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: setObject(int,Object) can not convert Java String object to backend's Integer type
@ 2013-01-08 11:59 Chen Huajun <chenhj@cn.fujitsu.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 0 replies; 3+ messages in thread
From: Chen Huajun @ 2013-01-08 11:59 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc
Dave
> This link http://docs.oracle.com/javase/1.3/docs/guide/jdbc/getstart/mapping.html should clarify things. The mapping is actually String to char, varchar, or longvarchar.
oh,I could not find so detailed description in my JDBC 4.0 Specification(a pdf file).
And mistaked the setObject(int,Object,int) and setObject(int,Object).
BTW:
In Oracle,the conversion seem be OK (my test was String -> NUMERIC).
That's why i pay attention to this problem.
Thanks!
Regards,
Chen Huajun
(2013/01/08 19:15), Dave Cramer wrote:
> Chen,
>
> This link http://docs.oracle.com/javase/1.3/docs/guide/jdbc/getstart/mapping.html should 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@cn.fujitsu.com <mailto:chenhj@cn.fujitsu.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@postgresql.org <mailto:pgsql-jdbc@postgresql.org>)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>
>
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2013-01-08 11:59 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-01-08 11:04 setObject(int, Object) can not convert Java String object to backend's Integer type Chen Huajun <chenhj@cn.fujitsu.com>
2013-01-08 11:15 ` Re: setObject(int,Object) can not convert Java String object to backend's Integer type Dave Cramer <pg@fastcrypt.com>
2013-01-08 11:59 ` Re: setObject(int,Object) can not convert Java String object to backend's Integer type Chen Huajun <chenhj@cn.fujitsu.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox