From wzhipan@soe.ucsc.edu Thu Dec 2 05:14:57 2010 Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id D0DDF133740B for ; Thu, 2 Dec 2010 01:14:57 -0400 (AST) 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 69138-04; Thu, 2 Dec 2010 05:14:49 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-01.cse.ucsc.edu (mail-01.cse.ucsc.edu [128.114.48.32]) by mail.postgresql.org (Postfix) with ESMTP id 03B8F1337B8B; Thu, 2 Dec 2010 01:14:48 -0400 (AST) Received: from mail-01.cse.ucsc.edu (mail-01.cse.ucsc.edu [128.114.48.32]) by mail-01.cse.ucsc.edu (Postfix) with ESMTP id 98C221009B90; Wed, 1 Dec 2010 21:14:46 -0800 (PST) Date: Wed, 1 Dec 2010 21:14:46 -0800 (PST) From: Zhipan Wang To: pgsql-jdbc@postgresql.org Cc: pgsql-general@postgresql.org Message-ID: <3682665.914331291266886473.JavaMail.root@mail-01.cse.ucsc.edu> In-Reply-To: <1503640621.914211291266514731.JavaMail.root@mail-01.cse.ucsc.edu> Subject: ResultSet problem in JDBC MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_14709_917667117.1291266886471" X-Originating-IP: [76.126.57.100] X-Mailer: Zimbra 5.0.20_GA_3127.RHEL5_64 (ZimbraWebClient - FF3.0 (Win)/5.0.20_GA_3127.RHEL5_64) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.909 tagged_above=-5 required=5 tests=BAYES_00=-1.9, HTML_MESSAGE=0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201012/52 X-Sequence-Number: 170343 ------=_Part_14709_917667117.1291266886471 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Hi all, I am writing a Java program using postgres. When I run my program, I got the following error message: Exception in thread "main" org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of org.postgresql.jdbc4.Jdbc4ResultSet. Use setObject() with an explicit Types value to specify the type to use. at org.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statement.java:1772) at org.postgresql.jdbc3g.AbstractJdbc3gStatement.setObject(AbstractJdbc3gStatement.java:37) at org.postgresql.jdbc4.AbstractJdbc4Statement.setObject(AbstractJdbc4Statement.java:46) at Cracking.testMethod(Cracking.java:619) at GetConnection.main(GetConnection.java:97) My code that caused this problem is: Statement st = c.createStatement(); ResultSet r = st.executeQuery("select unnest(col0) from relation2_col1 where keyValue<500"); PreparedStatement sql = c.prepareStatement( "SELECT col1 FROM relation2 WHERE col0 IN ?"); sql.setObject(1, r); ResultSet result = sql.executeQuery(); I am using Eclipse, and there is no warning for this code. Can't a result set be used in another query? How do I correct it? ------=_Part_14709_917667117.1291266886471 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable <= div style=3D'font-family: Times New Roman; font-size: 12pt; color: #000000'= >
Hi all,
I am writing a Java prog= ram using postgres. When I run my program, I got the following error messag= e:
Exception in thread "main" org.post= gresql.util.PSQLException: Can't infer the SQL type to use for
 an = instance of org.postgresql.jdbc4.Jdbc4ResultSet. Use setObject() with an ex= plicit Types value to specify the type to use.
    at org= .postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statement.j= ava:1772)
    at org.postgresql.jdbc3g.AbstractJdbc3gStat= ement.setObject(AbstractJdbc3gStatement.java:37)
    at o= rg.postgresql.jdbc4.AbstractJdbc4Statement.setObject(AbstractJdbc4Statement= .java:46)
    at Cracking.testMethod(Cracking.java:619)    at GetConnection.main(GetConnection.java:97)
= My code that caused this problem is:
= Statement st =3D c.createStatement();
ResultSet r =3D st.executeQuery("s= elect unnest(col0) from relation2_col1 where keyValue<500");
Prepared= Statement sql =3D c.prepareStatement( "SELECT col1 FROM relation2 WHERE col= 0 IN ?");
sql.setObject(1, r);
ResultSet result =3D sql.executeQuery(= );

I am using Eclipse, and there is no warning for this code. =
Can't a result set be used in another query? How do I correct it?
<= /div>
------=_Part_14709_917667117.1291266886471-- From craig@postnewspapers.com.au Thu Dec 2 06:44:46 2010 Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 009191337B7A for ; Thu, 2 Dec 2010 02:44:46 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 41663-08; Thu, 2 Dec 2010 06:44:38 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [173.230.139.50]) by mail.postgresql.org (Postfix) with ESMTP id A0D811337B55; Thu, 2 Dec 2010 02:44:38 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by www.postnewspapers.com.au (Postfix) with ESMTP id 5658914A7; Thu, 2 Dec 2010 01:44:37 -0500 (EST) X-Virus-Scanned: amavisd-new at postnewspapers.com.au.com Received: from www.postnewspapers.com.au ([127.0.0.1]) by localhost (www.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 4qfjwZUG8Q9L; Thu, 2 Dec 2010 01:44:36 -0500 (EST) Received: from mail.postnewspapers.com.au (ppp171-128.static.internode.on.net [150.101.171.128]) by www.postnewspapers.com.au (Postfix) with ESMTP id 7302219; Thu, 2 Dec 2010 01:44:36 -0500 (EST) Received: from [10.0.0.53] (wallace.localnet [10.0.0.53]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 6925C200B; Thu, 2 Dec 2010 14:44:35 +0800 (WST) Message-ID: <4CF74051.7010102@postnewspapers.com.au> Date: Thu, 02 Dec 2010 14:44:33 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100423 Thunderbird/3.0.4 MIME-Version: 1.0 To: Zhipan Wang CC: pgsql-jdbc@postgresql.org, pgsql-general@postgresql.org Subject: Re: [JDBC] ResultSet problem in JDBC References: <3682665.914331291266886473.JavaMail.root@mail-01.cse.ucsc.edu> In-Reply-To: <3682665.914331291266886473.JavaMail.root@mail-01.cse.ucsc.edu> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201012/55 X-Sequence-Number: 170346 On 02/12/10 13:14, Zhipan Wang wrote: > Statement st = c.createStatement(); > ResultSet r = st.executeQuery("select unnest(col0) from relation2_col1 > where keyValue<500"); > PreparedStatement sql = c.prepareStatement( "SELECT col1 FROM relation2 > WHERE col0 IN ?"); > sql.setObject(1, r); > ResultSet result = sql.executeQuery(); You appear to be trying to implement a subquery client-side. Why not just use: PreparedStatement sql = c.prepareStatement( "SELECT col1 FROM relation2 WHERE col0 IN "+ "(SELECT unnest(col0) from relation2_col1 where keyValue<500" ); ? It's hard to know whether the above is correct because you've failed to provide your schema, but something along those lines seems to fit your intent from the code above. > I am using Eclipse, and there is no warning for this code. No, Eclipse can't know the details of how every JDBC driver works. > Can't a result set be used in another query? How do I correct it? Either build an array with the contents of the resultset and pass that, or avoid the weirdness by using a subquery directly. -- System & Network Administrator POST Newspapers