Java OCA OCP Practice Question 2924

Question

Suppose that you have a table animal with three rows.

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

What does the following output?.

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

   ResultSet rs = stmt.executeQuery(sql)) { 
   rs.absolute(0); 
   rs.next(); 
   System.out.println(rs.getString(1)); 
} 
  • A. SQL
  • B. Javascript
  • C. Java
  • D. The code does not compile.
  • E. A SQLException is thrown.


A.

Note

The call to absolute(0) moves the cursor to a location immediately before the results, and then next() goes to the first row, so the answer is choice A.




PreviousNext

Related