Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 510A31337B43 for ; Tue, 5 Apr 2011 09:57:02 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 71825-02 for ; Tue, 5 Apr 2011 12:56:53 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og123.obsmtp.com (exprod7og123.obsmtp.com [64.18.2.24]) by mail.postgresql.org (Postfix) with ESMTP id 4DF7113364DE for ; Tue, 5 Apr 2011 09:56:51 -0300 (ADT) Received: from mail-ey0-f172.google.com ([209.85.215.172]) (using TLSv1) by exprod7ob123.postini.com ([64.18.6.12]) with SMTP ID DSNKTZsRk1hXFZAswtvIwFaH7Tu0+KansxkE@postini.com; Tue, 05 Apr 2011 05:56:52 PDT Received: by eye13 with SMTP id 13so107754eye.3 for ; Tue, 05 Apr 2011 05:56:50 -0700 (PDT) Received: by 10.14.124.5 with SMTP id w5mr3917308eeh.176.1302008209720; Tue, 05 Apr 2011 05:56:49 -0700 (PDT) Received: from [192.168.1.183] (dsl-hkibrasgw2-ff7ac300-240.dhcp.inet.fi [88.195.122.240]) by mx.google.com with ESMTPS id r48sm3977390eei.9.2011.04.05.05.56.45 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 05 Apr 2011 05:56:46 -0700 (PDT) Message-ID: <4D9B1184.9090404@enterprisedb.com> Date: Tue, 05 Apr 2011 15:56:36 +0300 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fi-FI; rv:1.9.1.16) Gecko/20110307 Icedove/3.0.11 MIME-Version: 1.0 To: Daron Ryan CC: pgsql-jdbc@postgresql.org Subject: Re: PreparedStatement for set membership (The IN operator) References: <4D9AC223.4000602@gmail.com> <4D9AD284.1090306@enterprisedb.com> <4D9B0D6C.70707@gmail.com> In-Reply-To: <4D9B0D6C.70707@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201104/24 X-Sequence-Number: 21750 On 05.04.2011 15:39, Daron Ryan wrote: > Thanks Heikki. I have tried using the setArray method but I am still > running into an error. > > Exception in thread "main" org.postgresql.util.PSQLException: Unknown > type _INTEGER. > at > org.postgresql.jdbc2.AbstractJdbc2Statement.setArray(AbstractJdbc2Statement.java:2800) > > at dictionary.test.Main.main(Main.java:85) > > This is the Array implementation I have created. > http://pastebin.com/tkzPRL4A Starting with JDBC4, you can use conn.createArrayOf() function. No need to create a custom Array class anymore. This is what we have in the test suite: public void testCreateArrayOfInt() throws SQLException { PreparedStatement pstmt = _conn.prepareStatement("SELECT ?::int[]"); Integer in[] = new Integer[3]; in[0] = 0; in[1] = -1; in[2] = 2; pstmt.setArray(1, _conn.createArrayOf("int4", in)); ResultSet rs = pstmt.executeQuery(); assertTrue(rs.next()); Array arr = rs.getArray(1); Integer out[] = (Integer [])arr.getArray(); assertEquals(3, out.length); assertEquals(0, out[0].intValue()); assertEquals(-1, out[1].intValue()); assertEquals(2, out[2].intValue()); } -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com