Java OCA OCP Practice Question 2224

Question

Given an updatable ResultSet that contains the following and this code, what does the code snippet output?

color count
character varying(255) integer
black 20
blue5
red 0
rs.afterLast(); 
rs.previous(); 
rs.updateInt(2, 10); 


rs = stmt.executeQuery("select * from pens where color = 'red'"); 
while (rs.next()) { 
   System.out.println(rs.getInt(2)); 
} 
  • A. 0
  • B. 10
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


A.

Note

This code tries to update a cell in a ResultSet.

However, it does not call updateRow() to actually apply the changes in the database.

This means the SELECT query does not see the changes and outputs the original value of 0.

Option A is correct.




PreviousNext

Related