• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CachedRowSet : Method acceptChanges()

 
Thomas Hauck
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reviewing the order of operations for updating rows in a table using the methods of
CachedRowSet through the following example



“stm” is valid reference to a Statement.
Note: Consider the following table below 'mathematicians' representing
a snapshot of the 'mathematicians' table.
In this example, only the column ID is important and I was unable to format the table elegantly as in Word or HTML.
----------------------------------------------------------------------------------------------
ID | FName | LName | Birthday | Country
58 | Carl |Gauss | 1777-04-30 | Germany
89 | Bernhard | Riemann | 1826-09-17 | Germany
103 | Issac | Newton | 1642-12-25 | England
115 | Jacob | Bernoulli | 1655-12-27 | Italy
124 | Pierre | Laplace | 1749-03-23 | France
----------------------------------------------------------------------------------------------

Because the method acceptChanges() was not called on line A, the changes will not be applied to the data source,
and upon executing the select statement, the output will be

58 89 103 115 124

In this code, we have obtained a CachedRowSet by using the constructor of the CachedRowSetImpl class.
crs.absolute(3); moves the cursor of the CachedRowSet “crs” to the 3rd row.
crs.updateInt(1, 42); changes the 1st column value of the 3rd row from 103 to 42

Updating a CachedRowSet object is similar to updating a ResultSet object.
However, because the rowset is not connected to its data source while it is being updated,
it must take an additional step to effect changes in its underlying data source.
So after calling the suitable update method, we should call the acceptChanges() method to have updates written to the data source.
Therefore the existing ID values will be printed as the output.

Question:
If we had called the method acceptChanges() on “line A”, would the correct output have been

58 89 42 115 124

Please confirm.
 
Bernhard Goetz
Ranch Hand
Posts: 57
1
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thomas,
did you try to run your code?

Regards, Bernhard
 
Thomas Hauck
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bernhard,

This is a theoretical problem and I do not have access to a relational database to run the code.

If I could run the code and see the output I probably would not have posted the question here.

I am doing a walkthrough of the code on paper.

Question:
If we had called the method acceptChanges() on “line A”, would the correct output have been

58 89 42 115 124

-----
 
Bernhard Goetz
Ranch Hand
Posts: 57
1
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. There's a compilation error.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic