Re: updatable resultsets -> SQLException: -1

From: Kris Jurka <books(at)ejurka(dot)com>
To: Guido Fiala <guido(dot)fiala(at)dka-gmbh(dot)de>
Cc: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: updatable resultsets -> SQLException: -1
Date: 2004-01-20 08:13:23
Message-ID: Pine.LNX.4.33.0401200307250.20628-200000@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Tue, 20 Jan 2004, Guido Fiala wrote:

>
> hallo all,
>
> i have a problem getting updatable resultsets working
> (Postgres 7.3.4, current pg73jdbc3.jar)
>
> basically i do:
>
> try {
> Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
> Resultset rs=stmt.executeQuery("Select * from sometable;");
> rs.first();//in my example it exists
> rs.updateInt("some_int",4);
> rs.updateString("some_string","some_value");
> rs.updateRow();
> } catch ( SQLException e ) {
> e.printStackTrace();
> }
>
> In that case i get an SQLException "no primary keys" whereas sometable
> definitely has primary key!!!

This is a known problem with the query parser. It has many deficiencies,
but the one manifesting itself here is that the trailing semi-colon is
picked up as part of the tablename. It tries to find the primary key for
"sometable;" which doesn't work. A workaround for this is to leave off
the semi-colon or put a space between it and the tablename.

> i tracked this down and found that using:
>
> Resultset rs=stmt.executeQuery("Select * from sometable for update of
> sometable;");
>
> let's me indeed update the values in the table (even if the resultset
> is opened not-CONCUR_UPDATABLE) !!, however there is still an
> "SQLException: -1" - whatever that means...
>
> >java.sql.SQLException: -1 > at
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.updateRow(AbstractJdbc2ResultSet.java:1082)
> >...
>

I don't understand what you're saying here. You claim that it works, but
it also throws an SQLException? Could we see some more code to produce
this? The attached file does not give me any errors.

Kris Jurka

Attachment Content-Type Size
updaters.java text/plain 923 bytes

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message dinakar 2004-01-20 11:23:44 Re: clarification needed in postgresql... + transactions...
Previous Message Guido Fiala 2004-01-20 07:46:51 updatable resultsets -> SQLException: -1