Dear All:
The following is my problem, I want to change rs's Column1 of last
record,
but when I update the Column1 to "123" and refreshRow, I try to get the
value
again, it doesn't get the real value "123", please tell me how to get the
real
"123", my DB is SQL 2000.
ps. if I using updateRow it will update in DB, but I don't want to update
DB.
Source Code
============================================================================
=
Connection conn = xxxx;
Statement stmt =
conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = null;
rs = stmt.executeQuery(
"Select * from Table_Name");
rs.last();
// get the Column1 value of last record
String first = rs.getString("Column1");
System.out.println(first);
// update to 123
rs.updateString("Column1","123");
rs.refreshRow();
// reget the Column1 value of last record after update
String second = rs.getString("Column1");
System.out.println(second);
rs.close();
conn.close();
Regards. Ahan
Andy Flowers - 25 Jun 2003 08:08 GMT
It's doing exactly what is is defined to do.
refreshRow does the following (as per the API docs)
"Refreshes the current row with its most recent value in the database. This
method cannot be called when the cursor is on the insert row.
The refreshRow method provides a way for an application to explicitly tell
the JDBC driver to refetch a row(s) from the database. An application may
want to call refreshRow when caching or prefetching is being done by the
JDBC driver to fetch the latest value of a row from the database. The JDBC
driver may actually refresh multiple rows at once if the fetch size is
greater than one. "
Thus you are seeing the real behaviour. If you wan a disconnected recordset
that you can play with off-line take a look at RowSet, and in particular
CachedRowSet
(http://www.javaworld.com/javaworld/jw-02-2001/jw-0202-cachedrow.html and
http://developer.java.sun.com/developer/technicalArticles/javaserverpages/cached
rowset/)
> Dear All:
> The following is my problem, I want to change rs's Column1 of last
[quoted text clipped - 9 lines]
>
> Source Code
============================================================================
> =
> Connection conn = xxxx;
> Statement stmt =
> conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
> ResultSet rs = null;
> rs = stmt.executeQuery(
[quoted text clipped - 13 lines]
>
> Regards. Ahan