Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / June 2003

Tip: Looking for answers? Try searching our database.

ResultSet refreshRow's problem ?

Thread view: 
Ahan Hsieh - 25 Jun 2003 05:23 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.