Exception when updating ResultSet - Mailing list pgsql-jdbc

From Stefan Reiser
Subject Exception when updating ResultSet
Date
Msg-id 4E57AB6E.2030308@tu-braunschweig.de
Whole thread Raw
List pgsql-jdbc
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)

Attachment

pgsql-jdbc by date:

Previous
From: Radosław Smogura
Date:
Subject: Re: SQL_ASCII charset conversion
Next
From: Ian Pilcher
Date:
Subject: PreparedStatement syntax extensions?