pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas O'Dowd <tom@uwillsee.com>
To: pgsql-jdbc@postgresql.org
Subject: Array support
Date: Thu, 21 Apr 2005 23:36:25 +0900
Message-ID: <1114094185.26958.22.camel@localhost.localdomain> (raw)

Hi all,

Currently using the driver postgresql-8.0-310.jdbc3.jar which I
downloaded a while ago. Just tried to use it to store a Java String
array but it throws an unimplemented exception.

A snippet of code that throws the exception would be:

	String[] strings = new String[] {"one", "two"};
	con.prepareStatement("INSERT INTO a (str_array) VALUES (?)";
	ps.setObject(1, strings, java.sql.Types.ARRAY);
	ps.executeUpdate();

(forgive any syntax errors, its just an example)

The exception thrown is:

Caused by: org.postgresql.util.PSQLException: Unsupported Types value: 2,003
    at org.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statement.java:1621)
    at org.postgresql.jdbc3.AbstractJdbc3Statement.setObject(AbstractJdbc3Statement.java:1436)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statement.java:1627)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    ... yada yada yada ...

According to the JDBC Spec, jdbc-3_0-fr-spec.pdf, the recommended way to
set an array is by using the ps.setObject() method. Is this easy to
implement? If someone can point me at some code, I can try implementing
it and sending in a patch. I haven't played with the driver code in
about 2 years. Unfortunately, I'm away on holidays for about a week
tomorrow, but if you have any ideas regarding implementation, I'll have
a go when I come back.

Should be possible to make it support multiple dimension arrays too I
guess. I haven't actually looked at the driver code yet. Oh I haven't
gotten around to testing ResultSet.getArray() yet, but I think I
remember reading somewhere that it was implemented.

Tom.

PS. I looked at trying to use PreparedStatement.setArray() but it takes
an java.sql.Array, which is just an Interface. I guess I could try
creating a class that implements Array and try passing that to
setArray() but I'm not even sure if that would work yet either. The
setObject() way suggested by the spec is definitely simpler.




view thread (7+ messages)  latest in thread

Message-ID: <1114094185.26958.22.camel@localhost.localdomain>
Permalink:  ../1114094185.26958.22.camel@localhost.localdomain/
Also on:    postgresql.org/message-id/1114094185.26958.22.camel@localhost.localdomain

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: tom@uwillsee.com
  Subject: Re: Array support
  In-Reply-To: <1114094185.26958.22.camel@localhost.localdomain>
  References: <1114094185.26958.22.camel@localhost.localdomain>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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