Skip site navigation (1) Skip section navigation (2)

Re: JDBC and arrays

From: Russell Francis <rfrancis(at)ev(dot)net>
To: Miroslav Šulc <miroslav(dot)sulc(at)startnet(dot)cz>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: JDBC and arrays
Date: 2007-02-02 14:40:39
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
Miroslav Šulc wrote:
> Thank you for explanation. If I still want to write inet[] data, is it
> sufficient to implement PGobject so it returns 'inet[]' type and '{
> "ip", "ip" }' value and pass that to setObject()?


I don't know if this will help you but awhile ago I implemented data
types for the JDBC driver for PGinet, PGmacaddr, PGcidr which have been
used successfully by a number of people including myself ;)  I would
still like to get them integrated into the driver but haven't had much
time to pursue it.  You can find the current version at

I have zero experience using them in an array but if you are using those
data types in PostgreSQL and using Java, the code might be useful to you.

Kind regards,

> -- 
> Miroslav Šulc
> Kris Jurka napsal(a):
>> 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[]");
>> 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
>> ---------------------------(end of broadcast)---------------------------
>> TIP 4: Have you searched our list archives?
> ---------------------------(end of broadcast)---------------------------
> TIP 7: You can help support the PostgreSQL project by donating at

In response to


pgsql-jdbc by date

Next:From: Kris JurkaDate: 2007-02-02 17:00:25
Subject: Re: JDBC and arrays
Previous:From: David BuchmannDate: 2007-02-02 10:30:17
Subject: Re: jdbc connection problem

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group