Array support - Mailing list pgsql-jdbc

From Thomas O'Dowd
Subject Array support
Date
Msg-id 1114094185.26958.22.camel@localhost.localdomain
Whole thread Raw
Responses Re: Array support
List 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.


pgsql-jdbc by date:

Previous
From: Oliver Siegmar
Date:
Subject: Interval support for Postgres
Next
From: Dennis Sacks
Date:
Subject: switching from 7.4.1 to 8.0-311 jdbc driver