pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: enishiseki@juno.com <enishiseki@juno.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: JDBC calling PL/pgSQL with array parameter
Date: Tue, 16 Nov 2004 21:45:54 -0500 (EST)
Message-ID: <Pine.BSO.4.56.0411162138570.11329@leary.csoft.net> (raw)
In-Reply-To: <20041116.093007.42.454@webmail25.nyc.untd.com>
References: <20041116.093007.42.454@webmail25.nyc.untd.com>



On Tue, 16 Nov 2004, enishiseki@juno.com wrote:

> I'm trying to call a PL/pgSQL function from a Java program using
> JDBC. The function takes an integer array as an input parameter,
> sums the elements of the array, and returns the sum.
> 
> I can successfully call the function from psql as:
>   SELECT testit('{1,2,3}')
> 
>     int [] intArray = {1,2,3};
>     stmt.setObject(2, intArray );
> 
> When I try to run the program, I get the error,
> "missing dimension value".
> 

The postgresql jdbc driver does not have support for using setOjbect with
array types.  If you enable statement logging you will see something like
the following command on the backend side:

SELECT testarrfunc('[I@fd13b5')

If you use the 8.0 driver you will get a better error message:

Exception in thread "main" org.postgresql.util.PSQLException: Can't infer 
the SQL type to use for an instance of [I. Use setObject() with an 
explicit Types value to specify the type to use.
        at 
org.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statement.java:1594)

Using the 7.4 driver you can do a setString(x, "{1,2,3}"), but this won't 
work with the 8.0 driver, for that you need a real java.sql.Array 
implementation.

Kris Jurka



view thread (2+ messages)

Message-ID: <Pine.BSO.4.56.0411162138570.11329@leary.csoft.net>
Permalink:  ../Pine.BSO.4.56.0411162138570.11329@leary.csoft.net/
Also on:    postgresql.org/message-id/Pine.BSO.4.56.0411162138570.11329@leary.csoft.net

 · 

reply

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, enishiseki@juno.com
  Subject: Re: JDBC calling PL/pgSQL with array parameter
  In-Reply-To: <Pine.BSO.4.56.0411162138570.11329@leary.csoft.net>
  References: <20041116.093007.42.454@webmail25.nyc.untd.com> <Pine.BSO.4.56.0411162138570.11329@leary.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