Re: PreparedStatement.setString

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Bert Hiri <bert(at)openwiki(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: PreparedStatement.setString
Date: 2005-04-22 08:12:37
Message-ID: 4268B1F5.1080302@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Ruediger Herrmann 2005-04-22 08:45:56 Re: isLast() and empty ResultSet
Previous Message Bert Hiri 2005-04-22 06:44:07 PreparedStatement.setString