From: Craig Ringer <craig@postnewspapers.com.au>
To: Zhipan Wang <wzhipan@soe.ucsc.edu>
Cc: pgsql-jdbc@postgresql.org
Cc: pgsql-general@postgresql.org
Subject: Re: [JDBC] ResultSet problem in JDBC
Date: Thu, 02 Dec 2010 14:44:33 +0800
Message-ID: <4CF74051.7010102@postnewspapers.com.au> (raw)
In-Reply-To: <3682665.914331291266886473.JavaMail.root@mail-01.cse.ucsc.edu>
References: <3682665.914331291266886473.JavaMail.root@mail-01.cse.ucsc.edu>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: craig@postnewspapers.com.au, wzhipan@soe.ucsc.edu, pgsql-general@postgresql.org
Subject: Re: [JDBC] ResultSet problem in JDBC
In-Reply-To: <4CF74051.7010102@postnewspapers.com.au>
References: <3682665.914331291266886473.JavaMail.root@mail-01.cse.ucsc.edu> <4CF74051.7010102@postnewspapers.com.au>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox