Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 53B1A1337B47 for ; Tue, 5 Apr 2011 10:43:06 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 48869-07 for ; Tue, 5 Apr 2011 13:42:54 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-vw0-f46.google.com (mail-vw0-f46.google.com [209.85.212.46]) by mail.postgresql.org (Postfix) with ESMTP id 7539B1337B43 for ; Tue, 5 Apr 2011 10:42:54 -0300 (ADT) Received: by vws1 with SMTP id 1so249174vws.19 for ; Tue, 05 Apr 2011 06:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=8xd7TgnMH7aS68F5AQHwk4X9Ju/AKaSaSgEAgIt7FdU=; b=nZzByNdeq4OVPEzw+oUF7DoPGDCBR15Vz1+IetKDS/P6QHjUM7H1bPOp5Ar3AiJbVn 67bMEtvgAFLylXAWiOUdkSyBGmiNGhvwjUedr+ERDaBf1BKmSisd6v5xnCDlnumvQN65 S9sxC5xWsZnvcUEh9EDTwGcGvCDrhmKrc+GgI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=Pc9R1855MsBHFZGcaUMb2WzH4fVFity4ZXB0XVrfDrYK+6nXA5icEwTEOzFGakD7ZU WD2mbNGO0qnb6N2MR6rtS0t82aZXvJm3/ZerA+yQIctNocSowdK8zaznaJul5zQ9QMOF 0eShT6Fm9NCJH1jTm3NalVsxqti8LdZgfi4k0= Received: by 10.52.65.20 with SMTP id t20mr11483733vds.22.1302010974777; Tue, 05 Apr 2011 06:42:54 -0700 (PDT) Received: from [114.74.147.157] ([114.74.147.157]) by mx.google.com with ESMTPS id dm9sm1381001vdb.43.2011.04.05.06.42.52 (version=SSLv3 cipher=OTHER); Tue, 05 Apr 2011 06:42:54 -0700 (PDT) Message-ID: <4D9B1C56.7010709@gmail.com> Date: Tue, 05 Apr 2011 23:12:46 +0930 From: Daron Ryan User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.9) Gecko/20100915 Thunderbird/3.1.4 MIME-Version: 1.0 To: Heikki Linnakangas 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> <4D9B1184.9090404@enterprisedb.com> In-Reply-To: <4D9B1184.9090404@enterprisedb.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.899 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001 X-Spam-Level: X-Archive-Number: 201104/25 X-Sequence-Number: 21751 On 5/04/2011 10:26 PM, Heikki Linnakangas wrote: > 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()); > } > Thanks, my code is working now. I changed my baseTypeName to int4 and after a few more fixes my code worked. Then I tried the Connection.createArrayOf method and that worked too.