Behavior question about updateable resultsets...



I have a question regarding a certain behavior of updateable
resultsets. If I update a column using any of the updateXXX methods and
then try to use the getXXX methods from the same column to see if it
updated the results locally and not on the server, I get the same old
value. I have to call updateRow() but that updates the underlying
database and still gives me the old value until I execute the same
query again and get a new resultset. Maybe the code below will clarify
my question more..

Connection con = null;
Statement stmt;
ResultSet rst;

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
System.out.println("Getting connection.");
con = DriverManager.getConnection(url);
System.out.println("Connection successful.");

String st = "select age,sname,snum FROM student;";
stmt =
con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rst = stmt.executeQuery(st);
rst.last();
System.out.print(rst.getInt(1)+" ");
System.out.print(rst.getString(2)+" ");
System.out.print(rst.getLong(3)+"\n");
rst.updateInt(1,23);
rst.updateRow();
System.out.print(rst.getInt(1)+" ");
System.out.print(rst.getString(2)+" ");
System.out.print(rst.getLong(3)+"\n");

The output is:
Getting connection.
Connection successful.
25 Edward Baker 578875478
25 Edward Baker 578875478

If I were the run the same code again, I get:
Getting connection.
Connection successful.
23 Edward Baker 578875478
23 Edward Baker 578875478

Any/all help is appreciated
Thanks

Devansh Dhutia
University of Iowa

.



Relevant Pages

  • Re: looking for opinons regarding best practices (jdbc, resultsets, and servlet design)
    ... (switching from JDBC to JNDI or a Web service, ... of data entity value objects around without keeping a connection open. ... back non-Cached RowSets or ResultSets requires an active connection. ... In real life one would likely want to log this exception. ...
    (comp.lang.java.programmer)
  • Re: looking for opinons regarding best practices (jdbc, resultsets, and servlet design)
    ... It allows passing of data entity value objects around without keeping a connection open. ... In a data-access-object layer approach, the DAO objects accept and pass back entities or collections, not ResultSets. ... In the MVC pattern there would be no servlet directly accessing JDBC. ... The controller is supposed to handle only parsing a request, its dispatch to model logic, then navigation to the subsequent view. ...
    (comp.lang.java.programmer)
  • RE: Optimizing performance
    ... Thank you for your very detailed post and benchmark source. ... only one ResultSet per connection simultaneously is another. ... multiple ResultSets on the same connection is not a requirement. ... The v1.2 driver does have a known performance issue around query timeouts. ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Re: best practices for subforms/subquerys
    ... I've read the article describing GetRows and GetString and ... it's values in an array, close my connection, do some HTML ... page and making multiple database calls. ... You would process the resultsets in asp by using NextRescordset: ...
    (microsoft.public.inetserver.asp.db)

Loading