pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
PreparedStatement.setString
2+ messages / 2 participants
[nested] [flat]

* PreparedStatement.setString
@ 2005-04-22 06:44 Bert Hiri <bert@openwiki.com>
  2005-04-22 08:12 ` Re: PreparedStatement.setString Oliver Jowett <oliver@opencloud.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Bert Hiri @ 2005-04-22 06:44 UTC (permalink / raw)
  To: pgsql-jdbc

Hi,

Suppose I have a table like:

    CREATE TABLE test
    ( id    DECIMAL(10)
    );

When executing the following statement from the psql command prompt:

    INSERT INTO test(id) VALUES ('12345');

That will succeed.

When executing the following from JDBC:

    PreparedStatement stmt =
        con.prepareStatement("INSERT INTO test(id) VALUES (?)");
    stmt.setString("12345");
    stmt.executeUpdate();

This will fail. With the message:

    Cause: ERROR: column "id" is of type numeric but expression is of type
character varying

I think this shouldn't fail. This exact same piece of Java code does work
with all other databases that I work with. And psql doesn't seem to mind
taking a string value either, so why should the PreparedStatement?




Regards,
Bert




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: PreparedStatement.setString
  2005-04-22 06:44 PreparedStatement.setString Bert Hiri <bert@openwiki.com>
@ 2005-04-22 08:12 ` Oliver Jowett <oliver@opencloud.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Oliver Jowett @ 2005-04-22 08:12 UTC (permalink / raw)
  To: Bert Hiri <bert@openwiki.com>; +Cc: pgsql-jdbc

Bert Hiri wrote:

>     PreparedStatement stmt =
>         con.prepareStatement("INSERT INTO test(id) VALUES (?)");
>     stmt.setString("12345");
>     stmt.executeUpdate();
> 
> This will fail. With the message:
> 
>     Cause: ERROR: column "id" is of type numeric but expression is of type
> character varying
> 
> I think this shouldn't fail. This exact same piece of Java code does work
> with all other databases that I work with. And psql doesn't seem to mind
> taking a string value either, so why should the PreparedStatement?

See http://archives.postgresql.org/pgsql-jdbc/2005-03/msg00060.php for
past discussion of this.

In summary: it might be a common idiom, but the JDBC spec doesn't
require drivers to support it, and there are protocol-level reasons why
it is not easy to support.

-O



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-04-22 08:12 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-04-22 06:44 PreparedStatement.setString Bert Hiri <bert@openwiki.com>
2005-04-22 08:12 ` Oliver Jowett <oliver@opencloud.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