Re: how to set a PreparedStatement column of XML type in 8.3?

From: dmp <danap(at)ttc-cmc(dot)net>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: how to set a PreparedStatement column of XML type in 8.3?
Date: 2007-12-13 18:11:46
Message-ID: 476175E2.4060507@ttc-cmc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

I'm sure I do not have the experience or knowledge to understand the
interaction between the PostgreSQL JDBC driver and the database. With
that said the issue though that Matt has brought up, this type mapping
concept, in the PostgreSQL JDBC driver for prepare statements parameters
is fine as long as the java.sql.preparedstatement standard supports that
type. Unfortunately the PostgreSQL database has some extended data types
that are not defined by the Java JDBC PreparedStatement and when one of
those types are not set appropriately the PostgreSQL JDBC throws the error
Matt has described. This then seems to force the developer to either create
a class for each of these non-supported data types or import the type
from the org.postgresql driver. In may case neither of these solutions
is viable without extending my code. I would like to maintain a generic
interface. Why can't we just pass a string or object, setString or setObject,
and have it accepted without a data type check in the PostgreSQL JDBC driver.
Yes if the database can not convert the data to the type then throw a error.
Other JDBC drivers allow an Integer type for example to set the value
through either setString() or setInt(). The JDBC driver doesn't seem to
care. The check/conversion seems to take place at the database level

dana.

>I'm using the 8.3dev-602 JDBC driver, trying to set the value of an "xml"
> type column in an 8.3 database. The driver keeps throwing exceptions like
>
> ERROR: column "xml" is of type xml but expression is of type character
> varying
>
> I've tried a variety of different ways, including pstmt.setString,
> pstmt.setObject, and pstmt.setObject passing in Types.OTHER.
>
> What is the correct way to set a statement parameter value for an xml
> column?
>
> Thanks,
> m@

> I am able to work around the issue by setting a PGObject value with the
> type set to "xml" and the value my XML String. Is this the way the driver
> is expected to work, or should it map Strings to the xml type
> automatically in 8.3?

-- m@

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Altaf Malik 2007-12-13 19:09:49 Re: JDBC causing the connection to close after executing a COPY command
Previous Message Kris Jurka 2007-12-13 16:49:18 Re: Synthesize support for Statement.getGeneratedKeys()?