Hi guys,
This question is regarding an explanation of answer on a question in one of the mock exam questions in the book: OCP Oracle Certified Professional
Java SE8 Programmer II Study Guide by Jeanne Boyarsky and Scott Selikoff.
tb067900.JaSE8PrgIISG.be2.31. Which of the following can fill in the blank correctly?
A. int num = rs.getInt(0);
B. int num = rs.getInt(1);
C. int num = rs.getInteger(0);
D. int num = rs.getInteger(1);
E. int num = rs.getObject(0);
F. int num = rs.getObject(1);
The answer is as follows:
In a ResultSet, columns are indexed starting with 1, not 0. Therefore, choices A, C, and E are incorrect. There are methods to get the column as an int or Object. However, choice F is incorrect because an Object cannot be assigned to a
String without a cast. Choice D is incorrect because the method is not named getInteger().
I think the explanation should say “an Object cannot be assigned to an
int” rather than “an Object cannot be assigned to a String”.
In addition to I have a question on the phrase “There are methods to get the column as an int or Object.” At first I thought would be there only 2 methods getInt() and getObject() but there are a lot of methods for example getString().
Is correct the expression? I'm not english mother-tongue therefore I not sure the phrase expresses there are other methods more than int and object.