X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B0828DB611 for ; Sun, 13 Nov 2005 20:16:32 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 98324-10 for ; Mon, 14 Nov 2005 00:16:29 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from net2.micro-automation.com (net2.micro-automation.com [64.7.141.29]) by svr1.postgresql.org (Postfix) with SMTP id B5DA3D6D59 for ; Sun, 13 Nov 2005 20:16:30 -0400 (AST) Received: (qmail 32292 invoked from network); 14 Nov 2005 00:16:33 -0000 Received: from dcdsl.ebox.com (HELO ?192.168.1.2?) (davec@64.7.143.116) by net2.micro-automation.com with SMTP; 14 Nov 2005 00:16:33 -0000 In-Reply-To: <4bd3e1480511131556o58dbeae8y7a08dc55927010e0@mail.gmail.com> References: <4bd3e1480511120921y6359a0achab46a321b4802219@mail.gmail.com> <4bd3e1480511131556o58dbeae8y7a08dc55927010e0@mail.gmail.com> Mime-Version: 1.0 (Apple Message framework v746.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Cc: Kris Jurka , pgsql-jdbc@postgresql.org Content-Transfer-Encoding: 7bit From: Dave Cramer Subject: Re: passing array as parameters to PrepareStatement or callable statement.[setObject() or setArray()] Date: Sun, 13 Nov 2005 19:16:32 -0500 To: Assad Jarrahian X-Mailer: Apple Mail (2.746.2) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.022 required=5 tests=[AWL=0.022] X-Spam-Score: 0.022 X-Spam-Level: X-Archive-Number: 200511/104 X-Sequence-Number: 14202 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> map) {return null;} public Object getArray(long index, int count) {return null;} public Object getArray(long index, int count, Map> map) {return null;} public ResultSet getResultSet() {return null;} public ResultSet getResultSet(Map> map) {return null;} public ResultSet getResultSet(long index, int count) {return null;} public ResultSet getResultSet(long index, int count, Map> 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 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 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 >