Array support

From: Thomas O'Dowd <tom(at)uwillsee(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Array support
Date: 2005-04-21 14:36:25
Message-ID: 1114094185.26958.22.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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.

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dennis Sacks 2005-04-21 15:02:10 switching from 7.4.1 to 8.0-311 jdbc driver
Previous Message Boris Kirzner 2005-04-21 12:39:03 Re: Bug in storing Timestamp