java – ResultSet. TYPE_ SCROLL_ Sensitive behavior

I'm interested in type_ SCROLL_ The behavior of resultset of sensitive type is confused

My understanding of this is:

>I execute a select query and return the result set I print out the value of a specific column in the first row. > Then I execute thread Sleep (10000), pause the program for 10 seconds. > When the program is dormant, I manually update the same column in the database (through the SQL prompt). > After 10 seconds, I print the values of the same column in the first row of the result set again

In step 4, I want to print column values that are different from those printed in step 1 But I always get the same value (even if the type of my resultset is scroll_type_sensitive)

Did I misunderstand anything here?

The following is the code I use

private void doStuff() throws Exception
{
    final String query = "select * from suppliers where sup_id=420";

    Statement stmt = this.con.createStatement(
        ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

    ResultSet rs = stmt.executeQuery(query);

    rs.next();

    System.out.println("City : " + rs.getString("city"));

    Thread.sleep(10000); // While this executes,I do a manual update !

    System.out.println("City : " + rs.getString("city"));
}

Solution

Yes You must get the latest status of the table again by starting select yourself or calling resultset refreshRow(). Also, read resultset. Before using it Refreshrow(), otherwise you may get unexpected results

About type_ SCROLL_ Doc status of sensitive,

This simply means that it is sensitive to changes made by others in the same resultset object To understand this concept, I suggest you take a look at the official JDBC tutorial: updating tables

OK, edit my post to include specific lines from the original tutorial,

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>