Re: AJ1Stmt.setObject()

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Brian Olson <bql(at)bolson(dot)org>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: AJ1Stmt.setObject()
Date: 2004-04-04 00:03:53
Message-ID: 406F50E9.9060702@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Brian Olson wrote:
> I think AbstractJdbc1Statement.setObject(int,Object) needs to know how
> to handle Java array types.

How do you specify how to interpret the elements of the array? e.g. how
should this be handled? :

Object[] awkwardArray = new Object[] { new Integer(42), "42", "foo" };
statement.setObject(1, awkwardArray);

> My problem is that I don't see any other way in jdbc to set array
> elements of rows. So, this must be it, though unimplemented here.

JDBC2's PreparedStatement.setArray() is the standard way: you wrap the
underlying array in an appropriate Array implementation of your own.
This also solves the problem of deciding how to interpret the array
elements: the Array interface allows you to explicitly provide a SQL
type for the elements.

However the CVS driver does not implement setArray usefully for this
case. I have an unapplied patch that was posted to the list some time
ago that implements this (getting quite old now..), which is a bit of a
nasty hack but does the job. See
http://archives.postgresql.org/pgsql-jdbc/2003-07/msg00294.php

-O

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Bob Bie 2004-04-04 17:24:40 commit after select
Previous Message Oliver Jowett 2004-04-03 23:52:05 Re: Storing Large Objects: ClassCastException