pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dave Cramer <pg@fastcrypt.com>
To: Assad Jarrahian <jarraa@gmail.com>
Cc: Kris Jurka <books@ejurka.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: passing array as parameters to PrepareStatement or callable statement.[setObject() or setArray()]
Date: Sun, 13 Nov 2005 19:16:32 -0500
Message-ID: <A427CF93-7A30-483A-B98C-FD19B60733F4@fastcrypt.com> (raw)
In-Reply-To: <4bd3e1480511131556o58dbeae8y7a08dc55927010e0@mail.gmail.com>
References: <4bd3e1480511120921y6359a0achab46a321b4802219@mail.gmail.com>
	<Pine.BSO.4.61.0511130347040.6118@leary.csoft.net>
	<4bd3e1480511131556o58dbeae8y7a08dc55927010e0@mail.gmail.com>

This is from a previous post.

Dave
public static Array convertIntegerToPgSqlArray(final int[] p) {
     if(p == null || p.length < 1) return null;
     Array a = new Array() {
       public String getBaseTypeName() {return "int4";}
       public int getBaseType()  {return 0;}
       public Object getArray()  {return null;}
       public Object getArray(Map<String, Class<?>> map)  {return null;}
       public Object getArray(long index, int count)  {return null;}
       public Object getArray(long index, int count, Map<String,  
Class<?>> map)  {return null;}
       public ResultSet getResultSet()  {return null;}
       public ResultSet getResultSet(Map<String, Class<?>> map)   
{return null;}
       public ResultSet getResultSet(long index, int count)  {return  
null;}
       public ResultSet getResultSet(long index, int count,  
Map<String, Class<?>> map) {return null;}

       public String toString() {
         String fp = "{";
         if(p.length == 0) {
         } else {
           for(int i = 0; i < p.length - 1; i++) fp += p[i] + ",";
           fp += p[p.length - 1];
         }
         fp+="}";
         return fp;
       }
     };

On 13-Nov-05, at 6:56 PM, Assad Jarrahian wrote:

> Hi Kris and all,
>   So I did a quick google search and found out all I need in my new
> class that implements Array is getBaseType() and toString() [I am not
> sure this is true since it is not working! Either that or I am doing
> something wrong]
>
> Code below
>
> public class IDArray implements Array{
>         protected int[] myArray;
>
>         public IDArray(int[] temp ){
>           ....
>          }
> 	public int getBaseType() throws SQLException {
> 		return Types.INTEGER;
> 	}
>      	public 	String toString(){
> 		String temp = new String();
> 		temp+="{";
> 		for (int i=0;i<arraySize; ++i){
> 			temp += myArray[i];
> 				if (i!=arraySize-1)
> 					temp +=",";
> 		}
> 		temp+="}";
> 		return temp;
> 	}
> }
>
>
> When I call it in my java code using
> 	IDArray LM_IDs = new IDArray(new int[]{3,4,5});
> 	getAssociatedLMs.setObject(1, LM_IDs, java.sql.Types.ARRAY);
>
> I get an exception thrown (I cant figure this one out).
> -1 Unknown type _null. [errorCode  message]
>
> Any pointers help, would be much appreciated. Thanks.
>
> -assad
>
>
> On 11/13/05, Kris Jurka <books@ejurka.com> wrote:
>>
>>
>> On Sat, 12 Nov 2005, Assad Jarrahian wrote:
>>
>>> Hello all,
>>>  my apologies if this question has been asked before. I looked
>>> through the archives could not find the relevant info (if I  
>>> overlooked
>>> something, sorry).
>>>
>>> int[] intarray = new int[1];
>>> getAssociatedLMs.setObject(1, intarray, java.sql.Types.ARRAY);
>>> //getAssociatedLM's is a callable statement ("{call getLMs(?,?) }  
>>> ");
>>>
>>> so I get a compilation error saying
>>> org.postgresql.util.PSQLException: Cannot cast an instance of [I to
>>> type Types.ARRAY
>>
>> Currently the driver only supports passing a specific  
>> implementation of
>> java.sql.Array to setObject (and setArray).  Other people have posted
>> helper classes to transform some specific java array types to
>> java.sql.Array, but these have not been generalized and added to the
>> driver.
>>
>> Kris Jurka
>>
>
> ---------------------------(end of  
> broadcast)---------------------------
> TIP 6: explain analyze is your friend
>




view thread (7+ messages)  latest in thread

Message-ID: <A427CF93-7A30-483A-B98C-FD19B60733F4@fastcrypt.com>
Permalink:  ../A427CF93-7A30-483A-B98C-FD19B60733F4@fastcrypt.com/
Also on:    postgresql.org/message-id/A427CF93-7A30-483A-B98C-FD19B60733F4@fastcrypt.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: pg@fastcrypt.com, jarraa@gmail.com, books@ejurka.com
  Subject: Re: passing array as parameters to PrepareStatement or callable statement.[setObject() or setArray()]
  In-Reply-To: <A427CF93-7A30-483A-B98C-FD19B60733F4@fastcrypt.com>
  References: <4bd3e1480511120921y6359a0achab46a321b4802219@mail.gmail.com> <Pine.BSO.4.61.0511130347040.6118@leary.csoft.net> <4bd3e1480511131556o58dbeae8y7a08dc55927010e0@mail.gmail.com> <A427CF93-7A30-483A-B98C-FD19B60733F4@fastcrypt.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