pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: J. <sweepingoar@yahoo.com>
To: pgsql-jdbc@postgresql.org
Subject: arrays as parameters in callableStatements
Date: Sun, 14 May 2006 19:56:06 -0700 (PDT)
Message-ID: <20060515025606.79891.qmail@web54215.mail.yahoo.com> (raw)

I've got a PL/pgSQL stored function in my database and I'm trying to  figure out how to call it from my admin script.  Some of the  parameters are ArrayList objects of strings and it returns an array  that I want to read to determine what the function actually did.   Here is the function header(?):
  
  CREATE OR REPLACE FUNCTION add_thing( 
  varchar,     --  name:varchar               ($1) 
  integer,     --  itemNum:integer                ($2) 
  varchar,     -- owner:varchar           ($3) 
  varchar,     -- image_url:varchar         ($4) 
  varchar,     -- specs_url:varchar        ($5) 
  varchar[],   -- categories[]:varchar           ($6) 
  varchar[],   -- component_name[]:varchar ($7) 
  varchar[],   -- component_id[]:varchar   ($8) 
  date[],      --  component_date[]:date             ($9) 
  varchar[]    -- componentImage_url[]:varchar   ($10) 
  ) RETURNS varchar[] as ' 
  
  Here is how I'm trying to call it in Java:
  
              // Turn transactions off.
              connection.setAutoCommit(false);
              // Procedure call.
               CallableStatement stmt = connection.prepareCall("{ ? = call add_thing(  ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) }");
              stmt.registerOutParameter(1, Types.ARRAY);
              stmt.setString(2, name);
              stmt.setInt(3, itemNum);
              stmt.setString(4, owner);
              stmt.setString(5, item_url);
              stmt.setString(6, specs);
              stmt.setObject(7, compNames);
              stmt.setObject(8, compIds);
              stmt.setObject(9, compDates);
              stmt.setObject(10, compURL);
              stmt.execute();
              String[] results = stmt.getArray(1);
              stmt.close();
  
  I'm getting a compiler error "Incompatible Types" on the second to last  line.  Looking at the API to me it seems like that's how it should  work.  I'm thinking of trying getResultSet()  instead, but since this is only the compile stage I'm asking for some  advice in case I'm way off base (in particular, aside from the error  mentioned I'm concerned about IN params 7-10 being written  correctly).  Thanks.
  
  -Jason
    
		
---------------------------------
Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2ยข/min or less.

view thread (4+ messages)  latest in thread

Message-ID: <20060515025606.79891.qmail@web54215.mail.yahoo.com>
Permalink:  ../20060515025606.79891.qmail@web54215.mail.yahoo.com/
Also on:    postgresql.org/message-id/20060515025606.79891.qmail@web54215.mail.yahoo.com

 · 

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: sweepingoar@yahoo.com
  Subject: Re: arrays as parameters in callableStatements
  In-Reply-To: <20060515025606.79891.qmail@web54215.mail.yahoo.com>
  References: <20060515025606.79891.qmail@web54215.mail.yahoo.com>

* 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