I’m trying to throw together a quick JDBC app using Postgres as the DB and am running into an interesting issue.
I currently have 2 tables, table1 and table2.
CREATE TABLE table1
(
a character varying NOT NULL,
b integer NOT NULL,
CONSTRAINT table1_pkey PRIMARY KEY (b)
)
CREATE TABLE table2
(
c character varying NOT NULL,
d integer,
CONSTRAINT table2_pkey PRIMARY KEY (c),
CONSTRAINT table2_d_fkey FOREIGN KEY (d),
REFERENCES table1(b) MATCH SIMPLE
ON UPDATE CSCADE ON DELETE CASCADE
)
As the backend of my program I’m SELECTing * and holding on to the ResultSet from my query. Each table has 1 row of simple values in it, doesn’t seem to matter what they are.
My statement is created with the flags ResultSet.TYPE_SCROLL_INSENSITIVE and ResultSet.CONCUR_UPDATE. Although I have tried SCROLL_SENSITIVE as well.
If I try the following (assumgin ResultSet rs/rs2 are valid and point to table1/table2 respectively:
rs.first(); // move to the first row (only row)
rs.updateInt(2, 50); // update our primary key, which is also the cascading fk
// 50 could be any number
print(rs); // Will show the old value
rs.updateRow();
print(rs); // Will show the new value
rs2.refreshRow(); // make sure we get the latest data from table2
print(rs2); // will show the old data?
I was hoping to see the new values due to the cascade. If I quit and re-run the app, not changing any input, then it will print the correct table2 values. I’m guessing this is due to re-running the SELECT statement. If I look at the table by running psql or pgadmin3, the values seem like they’re changing. So it seems like refreshRow() isn’t bringing down the latest stuff. Would anyone have any idea why?
I’m using:
- java 1.6_29
- postgresql-9.1-901.jdbc4.jar
Any help would be appreciated.
I hope you got it sorted out since it’s an old question but just for the record I post here a snippet that I tried and which is working for me: