pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedjdbc and ARRAYs
11+ messages / 6 participants
[nested] [flat]
* jdbc and ARRAYs
@ 2005-12-02 09:42 NosyMan <nosyman@gmail.com>
0 siblings, 1 reply; 11+ messages in thread
From: NosyMan @ 2005-12-02 09:42 UTC (permalink / raw)
To: pgsql-jdbc
Hi everyone,
I have some problems trying to use a preparedStatement with an array
parameter. The problem is I don't know how to do it :-(
CREATE OR REPLACE FUNCTION MyFunction( id INTEGER, anArray
VARCHAR[] )..........................
pstat = conn.prepareStatement("SELECT * FROM MyFunction(?,?)");
pstat.setInt(1, 30);
pstat.setArray(2, ??????????);
Can you tell me how can I construct the array for parameter number 2?
Thanks,
NosyMan
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: jdbc and ARRAYs
@ 2005-12-02 13:20 Dave Cramer <pg@fastcrypt.com>
parent: NosyMan <nosyman@gmail.com>
0 siblings, 1 reply; 11+ messages in thread
From: Dave Cramer @ 2005-12-02 13:20 UTC (permalink / raw)
To: NosyMan <nosyman@gmail.com>; +Cc: pgsql-jdbc
You have to implement the java.sql.Array interface and pass that in.
search the list, there's a few references to this question and some
code.
Dave
On 2-Dec-05, at 4:42 AM, NosyMan wrote:
> Hi everyone,
>
> I have some problems trying to use a preparedStatement with an array
> parameter. The problem is I don't know how to do it :-(
>
> CREATE OR REPLACE FUNCTION MyFunction( id INTEGER, anArray
> VARCHAR[] )..........................
>
>
> pstat = conn.prepareStatement("SELECT * FROM MyFunction(?,?)");
> pstat.setInt(1, 30);
> pstat.setArray(2, ??????????);
>
> Can you tell me how can I construct the array for parameter number 2?
>
> Thanks,
> NosyMan
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 6: explain analyze is your friend
>
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: jdbc and ARRAYs
@ 2005-12-02 16:14 Achilleus Mantzios <achill@matrix.gatewaynet.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 0 replies; 11+ messages in thread
From: Achilleus Mantzios @ 2005-12-02 16:14 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: NosyMan <nosyman@gmail.com>; pgsql-jdbc
O Dave Cramer Ýãñáøå óôéò Dec 2, 2005 :
> You have to implement the java.sql.Array interface and pass that in.
> search the list, there's a few references to this question and some
> code.
I think the easiest way to do this
is to simply construct your array strings,
and then deal with them as Strings.
>
> Dave
> On 2-Dec-05, at 4:42 AM, NosyMan wrote:
>
> > Hi everyone,
> >
> > I have some problems trying to use a preparedStatement with an array
> > parameter. The problem is I don't know how to do it :-(
> >
> > CREATE OR REPLACE FUNCTION MyFunction( id INTEGER, anArray
> > VARCHAR[] )..........................
> >
> >
> > pstat = conn.prepareStatement("SELECT * FROM MyFunction(?,?)");
> > pstat.setInt(1, 30);
> > pstat.setArray(2, ??????????);
> >
> > Can you tell me how can I construct the array for parameter number 2?
> >
> > Thanks,
> > NosyMan
> >
> >
> > ---------------------------(end of
> > broadcast)---------------------------
> > TIP 6: explain analyze is your friend
> >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>
--
-Achilleus
^ permalink raw reply [nested|flat] 11+ messages in thread
* JDBC and arrays
@ 2007-02-02 01:37 Miroslav Šulc <miroslav.sulc@startnet.cz>
0 siblings, 1 reply; 11+ messages in thread
From: Miroslav Šulc @ 2007-02-02 01:37 UTC (permalink / raw)
To: pgsql-jdbc
Hi,
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.
Thanks for any info.
--
Miroslav Šulc
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: JDBC and arrays
@ 2007-02-02 07:07 Kris Jurka <books@ejurka.com>
parent: Miroslav Šulc <miroslav.sulc@startnet.cz>
0 siblings, 1 reply; 11+ messages in thread
From: Kris Jurka @ 2007-02-02 07:07 UTC (permalink / raw)
To: Miroslav Šulc <miroslav.sulc@startnet.cz>; +Cc: pgsql-jdbc
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
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: JDBC and arrays
@ 2007-02-02 09:31 Miroslav Šulc <miroslav.sulc@startnet.cz>
parent: Kris Jurka <books@ejurka.com>
0 siblings, 2 replies; 11+ messages in thread
From: Miroslav Šulc @ 2007-02-02 09:31 UTC (permalink / raw)
To: pgsql-jdbc
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()?
--
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[]");
> 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
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: JDBC and arrays
@ 2007-02-02 14:40 Russell Francis <rfrancis@ev.net>
parent: Miroslav Šulc <miroslav.sulc@startnet.cz>
1 sibling, 1 reply; 11+ messages in thread
From: Russell Francis @ 2007-02-02 14:40 UTC (permalink / raw)
To: Miroslav Šulc <miroslav.sulc@startnet.cz>; +Cc: 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()?
Miroslav,
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
http://oak.cats.ohiou.edu/~rf358197/jdbc/2/
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,
Russ
>
> --
> 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[]");
>> 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
>> ---------------------------(end of broadcast)---------------------------
>> TIP 4: Have you searched our list archives?
>>
>> http://archives.postgresql.org
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: You can help support the PostgreSQL project by donating at
>
> http://www.postgresql.org/about/donate
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: JDBC and arrays
@ 2007-02-02 17:00 Kris Jurka <books@ejurka.com>
parent: Miroslav Šulc <miroslav.sulc@startnet.cz>
1 sibling, 1 reply; 11+ messages in thread
From: Kris Jurka @ 2007-02-02 17:00 UTC (permalink / raw)
To: Miroslav Šulc <miroslav.sulc@startnet.cz>; +Cc: pgsql-jdbc
On Fri, 2 Feb 2007, 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()?
That should work although you'll probably need to write _inet
instead of inet[]. The underscore variant is the the backend's true
datatype name and I'm not sure if it will accept the other version in this
context.
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: JDBC and arrays
@ 2007-02-03 19:25 Miroslav Šulc <miroslav.sulc@startnet.cz>
parent: Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 11+ messages in thread
From: Miroslav Šulc @ 2007-02-03 19:25 UTC (permalink / raw)
To: pgsql-jdbc
I got writing of inet[] working through object that implements PGobject
(you were right, it works only with _inet), but I cannot read inet[]. I
thought I'll get String[] through getArray(index).getArray() but instead
I get an exception on getArray(index). What is the correct way to read
inet[]?
Caused by: org.postgresql.util.PSQLException: Method
org.postgresql.jdbc3g.Jdbc3gArray.getArrayImpl(long,int,Map) is not
implemented.
at org.postgresql.Driver.notImplemented(Driver.java:728)
at
org.postgresql.jdbc2.AbstractJdbc2Array.getArrayImpl(AbstractJdbc2Array.java:228)
at
org.postgresql.jdbc2.AbstractJdbc2Array.getArray(AbstractJdbc2Array.java:71)
at
cz.startnet.utils.java.sql.ResultSetUtils.getValue(ResultSetUtils.java:253)
--
Miroslav Šulc
Kris Jurka napsal(a):
>
>
> On Fri, 2 Feb 2007, 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()?
>
> That should work although you'll probably need to write _inet instead
> of inet[]. The underscore variant is the the backend's true datatype
> name and I'm not sure if it will accept the other version in this
> context.
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: JDBC and arrays
@ 2007-02-03 19:41 Miroslav Šulc <miroslav.sulc@startnet.cz>
parent: Miroslav Šulc <miroslav.sulc@startnet.cz>
0 siblings, 0 replies; 11+ messages in thread
From: Miroslav Šulc @ 2007-02-03 19:41 UTC (permalink / raw)
To: pgsql-jdbc
I got it. I read it as string and then I parse the string to get the values.
--
Miroslav Šulc
Miroslav Šulc napsal(a):
> I got writing of inet[] working through object that implements
> PGobject (you were right, it works only with _inet), but I cannot read
> inet[]. I thought I'll get String[] through getArray(index).getArray()
> but instead I get an exception on getArray(index). What is the correct
> way to read inet[]?
>
> Caused by: org.postgresql.util.PSQLException: Method
> org.postgresql.jdbc3g.Jdbc3gArray.getArrayImpl(long,int,Map) is not
> implemented.
> at org.postgresql.Driver.notImplemented(Driver.java:728)
> at
> org.postgresql.jdbc2.AbstractJdbc2Array.getArrayImpl(AbstractJdbc2Array.java:228)
>
> at
> org.postgresql.jdbc2.AbstractJdbc2Array.getArray(AbstractJdbc2Array.java:71)
>
> at
> cz.startnet.utils.java.sql.ResultSetUtils.getValue(ResultSetUtils.java:253)
>
>
> --
> Miroslav Šulc
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: JDBC and arrays
@ 2007-02-07 03:48 Miroslav Šulc <miroslav.sulc@startnet.cz>
parent: Russell Francis <rfrancis@ev.net>
0 siblings, 0 replies; 11+ messages in thread
From: Miroslav Šulc @ 2007-02-07 03:48 UTC (permalink / raw)
To: ; +Cc: pgsql-jdbc
Russell,
thank you for the link. I have all the logic already implemented either
in my classes or I use system one (like java.net.Inet4Address) so what I
need (and have) is just a simple implementation of PGobject which
returns correct type and the value.
Best regards,
--
Miroslav Šulc
Russell Francis napsal(a):
> 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()?
>>
>
> Miroslav,
>
> 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
>
> http://oak.cats.ohiou.edu/~rf358197/jdbc/2/
>
> 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,
> Russ
>
^ permalink raw reply [nested|flat] 11+ messages in thread
end of thread, other threads:[~2007-02-07 03:48 UTC | newest]
Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-12-02 09:42 jdbc and ARRAYs NosyMan <nosyman@gmail.com>
2005-12-02 13:20 ` Dave Cramer <pg@fastcrypt.com>
2005-12-02 16:14 ` Achilleus Mantzios <achill@matrix.gatewaynet.com>
2007-02-02 01:37 JDBC and arrays Miroslav Šulc <miroslav.sulc@startnet.cz>
2007-02-02 07:07 ` Re: JDBC and arrays Kris Jurka <books@ejurka.com>
2007-02-02 09:31 ` Re: JDBC and arrays Miroslav Šulc <miroslav.sulc@startnet.cz>
2007-02-02 14:40 ` Re: JDBC and arrays Russell Francis <rfrancis@ev.net>
2007-02-07 03:48 ` Re: JDBC and arrays Miroslav Šulc <miroslav.sulc@startnet.cz>
2007-02-02 17:00 ` Re: JDBC and arrays Kris Jurka <books@ejurka.com>
2007-02-03 19:25 ` Re: JDBC and arrays Miroslav Šulc <miroslav.sulc@startnet.cz>
2007-02-03 19:41 ` Re: JDBC and arrays Miroslav Šulc <miroslav.sulc@startnet.cz>
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