Java OCA OCP Practice Question 2289

Question

Consider this program, and choose the best option describing its behavior (assume that the connection is valid):.

try (Statement statement = connection.createStatement();
      ResultSet resultSet = statement.executeQuery("SELECT * FROM contact")){
      System.out.println(resultSet.getInt("id") + "\t"
          + resultSet.getString("firstName") + "\t"
          + resultSet.getString("lastName") + "\t"
          + resultSet.getString("email") + "\t"
          + resultSet.getString("phoneNo"));
}
catch (SQLException sqle) {
      System.out.println("SQLException");
}
  • A. this program will print the following: SQLException.
  • B. this program will print the first row from contact.
  • C. this program will print all the rows from contact.
  • d. this program will report compiler errors.


A.

Note

the statement while (resultSet.next()) is missing.




PreviousNext

Related