Java OCA OCP Practice Question 2066

Question

Given the following code snippet and the table, what is the output of the following?.

rst_name                last_name /*from   w w  w.j av  a2s.c  o m*/
character varying(255)  character varying(255) 
Java                    Server 
Javascript              Client 
HTML                    Makup 
SQL                     Database 


try (Connection conn = DriverManager.getConnection(url); 
   Statement stmt = conn.createStatement(); 
   ResultSet rs = stmt.executeQuery( 
      "select * from people order by last_name asc")) { 

   rs.next(); 
   rs.next(); 
   System.out.print(rs.getString(1)); 
   System.out.print(" "); 
   rs.absolute(1); 
   System.out.print(rs.getString(1)); 
} 
  • A. Java SQL
  • B. SQL Java
  • C. The code compiles, but the output is neither of these.
  • D. The code throws a SQLException at runtime.


D.

Note

When creating the Statement, the code doesn't specify a result set type.

This means it defaults to TYPE_FORWARD_ONLY.

The absolute() method can only be called on scrollable result sets.

The code throws a SQLException, making Option D the answer.




PreviousNext

Related