Java OCA OCP Practice Question 3121

Question

Choose the correct option based on the following code snippet.

Assume that DbConnector.connectToDb() returns a valid Connection object and that the EMPLOYEE table has a column named CUSTOMERID of type VARCHAR(3).

ResultSet resultSet = null;/*from ww w. j  a v  a2s .  c  o m*/
try (Connection connection = DbConnector.connectToDb()) {
           // LINE_ONE
    Statement statement = connection.createStatement();
    resultSet = statement.executeQuery
                ("SELECT * FROM CUSTOMER WHERE CUSTOMERID = 1212"); // LINE_TWO
}
while (resultSet.next()){     // LINE_THREE
    resultSet.getString("CUSTOMERID");
}
  • a) this code results in a compiler error in line marked with the comment LINE_ONE
  • b) this code results in a compiler error in line marked with the comment LINE_TWO
  • c) this code results in a compiler error in line marked with the comment LINE_THREE
  • d) this code prints "1212" on the console and terminates
  • e) this code gets into an infinite loop and keeps printing "1212" on the console
  • f) this code throws SQLException


f)

Note

the try-with-resources block is closed before the while statement executes.

hence, call resultSet.next() results in making a call on the closed ResultSet object, thereby throwing an SQLException.




PreviousNext

Related