Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id CC7919FB431 for ; Mon, 12 Mar 2007 14:50:16 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 48055-07 for ; Mon, 12 Mar 2007 14:50:13 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by postgresql.org (Postfix) with ESMTP id A69CB9FB409 for ; Mon, 12 Mar 2007 14:50:12 -0300 (ADT) Received: from root by ciao.gmane.org with local (Exim 4.43) id 1HQoeo-0008Ks-Bq for pgsql-jdbc@postgresql.org; Mon, 12 Mar 2007 18:50:02 +0100 Received: from 217.6.22.218 ([217.6.22.218]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 12 Mar 2007 18:50:02 +0100 Received: from andreas.niemeyer by 217.6.22.218 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 12 Mar 2007 18:50:02 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Andreas Niemeyer Subject: Re: setArray Date: Mon, 12 Mar 2007 18:34:06 +0100 Lines: 72 Message-ID: References: <20070216115103.8tagbdi2edy8g8kk@webmail.versatel.nl> <45D6E075.7060504@startnet.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 217.6.22.218 User-Agent: Thunderbird 1.5.0.10 (Macintosh/20070221) In-Reply-To: <45D6E075.7060504@startnet.cz> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.499 tagged_above=0 required=5 tests=BAYES_50, RCVD_NUMERIC_HELO, SPF_HELO_PASS, SPF_PASS X-Spam-Level: * X-Archive-Number: 200703/96 X-Sequence-Number: 16810 Hi, Could you just provide a concrete code snippet? I would like to pass int[], String[], timestamp[] and float[] arrays. Thank you in advance, Andreas Miroslav Šulc schrieb: > Hi, > > I recently had to solve this too. What I did is: > > 1) I created class that implements java.sql.Array (it is sufficient to > implement getArray(), getBaseType(), getBaseTypeName() and toString(), > for details see Java API docs) + I added one extra method, > setArray(Class componentType, Object[] array), where componentType is > component type of the array, which I use for setting the array value > into the array > > 2) Then I use this code to set the array: > > final MyArray array = new MyArray(); > array.setArray(componentType, arrayValue); > pstm.setArray(index, array); > > HTH > > -- > Miroslav Šulc > > > > Alex Stienstra napsal(a): >> Hi, >> >> Iam trying to set an array in a prepared statement like this: >> >> PreparedStatement stmnt = ds.prepareStatement( >> "INSERT INTO trainingen (\"Atleet\", \"Datum\", \"Tijdstip\", >> \"Afstand\", \"Tijd (Zone)\") VALUES (?,?,?,?,?)" >> ); >> stmnt.setString(5, "{1,2,3,4,5,6}"); >> >> Assuming that the 5th parameter is an array of integer i get the >> follow error message: >> >> ERROR: column "Tijd (Zone)" is of type integer[] but expression is of >> type character varying >> >> I understood from previous discussions that the driver underwater will >> convert the parameter of setArray >> into a string representation like i do in the example above. I there >> any other way of setting an array >> field in a prepared statement? >> >> Alex. >> >> >> >> ---------------------------(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 > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Have you searched our list archives? > > http://archives.postgresql.org >