From: Stefan Reiser <s.reiser@tu-braunschweig.de>
To: pgsql-jdbc@postgresql.org
Subject: Exception when updating ResultSet
Date: Fri, 26 Aug 2011 16:19:26 +0200
Message-ID: <4E57AB6E.2030308@tu-braunschweig.de> (raw)
Hello,
i'd like to report a bug and suggest a patch:
- Suppose you have an updatable ResultSet with a query of the form
"SELECT foo AS bar FROM sometable".
- Now, if you try to make updates to the field "bar" an Exception is
thrown (it says that the field "foo" was not found).
The reason is that somewhere during updateString(...) in
AbstractJdbc2ResultSet there is a call to findColumn("foo") , which
fails, of course, because in the ResultSet there is no field labeled "foo".
Below there is a concrete example.
@Developers: Can you please take a look at the file attached and decide
whether you want to use it? It's for version 9.0 Build 801.
I'm using this since last december and it works just fine.
There's an earlier post with a more detailed description of the problem
and the patch:
http://archives.postgresql.org/pgsql-jdbc/2010-12/msg00084.php
Regards
Stefan Reiser
Example:
43 public static void main(String[] args) throws Exception {
44 Connection con = // ... setup connection ...
45 PreparedStatement ps = con.prepareStatement("SELECT
a_stationkey AS key, a_description AS desc FROM station WHERE
a_stationkey = 1234",
46 ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
47 ResultSet rs = ps.executeQuery();
48 rs.next();
49 rs.updateString("desc", "Hallo!"); // --Throws an exception,
see below--
50 rs.updateRow();
51 rs.close();
52 con.close();
53 }
Exception in thread "main" org.postgresql.util.PSQLException: The column
name a_stationkey was not found in this ResultSet.
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.findColumn(AbstractJdbc2ResultSet.java:2562)
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.isUpdateable(AbstractJdbc2ResultSet.java:1535)
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.checkUpdateable(AbstractJdbc2ResultSet.java:2661)
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.updateValue(AbstractJdbc2ResultSet.java:2929)
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.updateString(AbstractJdbc2ResultSet.java:1313)
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.updateString(AbstractJdbc2ResultSet.java:1398)
at Test.main(Test.java:49)
Attachments:
AbstractJdbc2ResultSet.java (text/x-java, 89.8K) download
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: s.reiser@tu-braunschweig.de
Subject: Re: Exception when updating ResultSet
In-Reply-To: <4E57AB6E.2030308@tu-braunschweig.de>
References: <4E57AB6E.2030308@tu-braunschweig.de>
* 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