Java OCA OCP Practice Question 2922

Question

Suppose that you have a table with three rows.

The names in those rows are Java, Javascript, and SQL.

What does the following output?.

String sql = "select name from animal"; 
try (Connection conn = DriverManager.getConnection("jdbc:derby:zoo"); 
   Statement stmt = conn.createStatement(); 

  ResultSet rs = stmt.executeQuery(sql)) { 
  rs.next(); /*from   w  w  w.j  a  va  2 s . c o m*/
  rs.previous(); 
  rs.previous(); 
  rs.next(); 
  rs.next(); 
  rs.absolute(2); 
  System.out.println(rs.getString(1)); 
} 
  • A. Java
  • B. Javascript
  • C. SQL
  • D. The code does not compile.
  • E. A SQLException is thrown.


E.

Note

By default, a Statement is not scrollable.

The first call to previous() throws a SQLException because the ResultSet type is TYPE_FORWARD_ONLY.




PreviousNext

Related