Java OCA OCP Practice Question 2068

Question

Given that the people table has 10 rows, what is the result of the following when using a driver that supports a scroll sensitive Resultset?.

String sql = "select count(*) from people"; 
try (Connection conn = DriverManager.getConnection(url); 
   Statement stmt = conn.createStatement(); 
   ResultSet rs = stmt.executeQuery(sql, 
      ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY)) { 

   rs.next(); /*from   w ww  .  j a  va  2s  .c  o m*/
   rs.absolute(0);                    // q1 
   System.out.print(rs.getInt(1));    // q2 
} 
  • A. 10
  • B. The code does not compile.
  • C. Line q1 throws a SQLException.
  • D. Line q2 throws a SQLException.


B.

Note

This code does not compile because the ResultSet options need to be supplied when creating the Statement object rather than when executing the query.

Since the code does not compile, Option B is correct.




PreviousNext

Related