From: Kris Jurka <books@ejurka.com>
To: Miroslav Šulc <miroslav.sulc@startnet.cz>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: JDBC and arrays
Date: Fri, 2 Feb 2007 02:07:43 -0500 (EST)
Message-ID: <Pine.BSO.4.64.0702020154310.31728@leary2.csoft.net> (raw)
In-Reply-To: <45C295F4.4030100@startnet.cz>
References: <45C295F4.4030100@startnet.cz>
On Fri, 2 Feb 2007, Miroslav Šulc wrote:
> I tried to find some info on how to work with arrays using PostgreSQL JDBC
> driver but didn't find anything useful except that I can implement
> java.sql.Array to get support for arrays. Can someone, please, send me a link
> on how to write and read array data using PostgreSQL JDBC driver or give me a
> brief explanation? I'm also interested how to work with inet[] arrays as they
> do not seem to be directly supported by JDBC API.
Reading arrays is pretty straightforward:
ResultSet rs = stmt.executeQuery("SELECT '{a,b}'::text[]");
rs.next();
Array arr = rs.getArray(1);
String s[] = (String)arr.getArray();
Writing arrays is not easy because prior to the JDBC4 spec there was no
way to create java.sql.Array objects without creating a class that
implements java.sql.Array yourself. Now JDBC4 offers
Connection.createArrayOf() which unfortunately we haven't implemented yet.
So while there is a light at the end of the tunnel you're still stuck
implementing java.sql.Array yourself. Check the mailing list for examples
of that.
Currently arrays of non-standard datatypes like inet are not supported.
Seems possible to do if you were willing to use PGobject for unknown
types, but no one has done it.
Also more complicated things like multi-dimensional arrays are note
supported.
Kris Jurka
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: books@ejurka.com, miroslav.sulc@startnet.cz
Subject: Re: JDBC and arrays
In-Reply-To: <Pine.BSO.4.64.0702020154310.31728@leary2.csoft.net>
References: <45C295F4.4030100@startnet.cz> <Pine.BSO.4.64.0702020154310.31728@leary2.csoft.net>
* 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