All,
I've been having this strange problem when I try to update ResultSets,
using the latest postgresql.jar (Feb 25, 2003). I have this simple table
create table tab (c0 int, c1 text, primary key(c0));
with one row of data:
1, 'old'
When I update the row using first() to position the insert:
********
String q = "select c0, c1 from tab";
Object o = null;
ResultSet rs = null;
Statement s =
conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
rs = s.executeQuery(q);
rs.first();
o = rs.getObject(2);
System.out.println("Old val: " + o);
rs.updateObject(2, "new");
rs.updateRow();
rs.absolute(1);
o = rs.getObject(2);
System.out.println("New val: " + o);
********
it works fine:
Old val: old
New val: new
Substituting absolute(1) for first() (which is supposed to be a
synonym), above, leads to the following:
Old val: new
Exception in thread "main" java.sql.SQLException
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.updateRow(AbstractJdbc2ResultSet.java:1077)
at com.sysd.sql.DbTableModel.main(DbTableModel.java:590)
Adding a second row of data doesn't change the outcome, nor does doing
an absolute(2).
The error is being caught at the bottom of the large updateRow() method,
so it's hard to tell what's happening. This is such a fundamental
operation that I'm sure I've done something wrong. (BTW, the problem
occurs in the pg-snapshot of last Friday, as well.) Before I dive into
the code, can anyone suggest what's wrong?
Thanks,
Rich Cullingford
System Detection, Inc
5 W 19th St, NY, NY