Given the records from the Employee table:



and given the code fragment:

Assume that:

The required database driver is configured in the classpath.
The appropriate database accessible with the URL, userName, and passWord exists.

What is the result?

A.
The Employee table is updated with the row:
112 Jack
and the program prints:
112 Jerry
B.
The Employee table is updated with the row:
112 Jack
and the program prints:
112 Jack
C.
The Employee table is not updated and the program prints:
112 Jerry
D. The program prints Exception is raised.

題解

第22行建立Statement物件時所傳入的resultSetType為TYPE_SCROLL_INSENSITIVE,因此除了可以用next來移動欄位指標之外,也可以使用afterLast、previous、absolute和relative等方法。TYPE_SCROLL_INSENSITIVE會保留原始從資料庫取得的資料,TYPE_SCROLL_SENSITIVE才會使用後來更動的資料。

while迴圈會執行三次,走訪完所有的結果列,此時eid為112的列的第二個欄位,原先的「Jerry」字串已被修改為「Jack」字串。但由於resultSetType為TYPE_SCROLL_INSENSITIVE,會保留一開始的結果,所以最後輸出「112 Jerry」。