Java OCA OCP Practice Question 2035

Question

Given the table books in the previous question and a ResultSet created by running this SQL statement, which option prints OCP?.

select title from cert where num_pages > 500.

A.   System.out.println(rs.getString());
B.   System.out.println(rs.getString("0"));
C.   System.out.println(rs.getString("1"));
D.   System.out.println(rs.getString("title"));


D.

Note

Option A does not compile because you have to pass a column index or column name to the method.

Options B and C compile.

However, there are not columns named 0 or 1.

Since these column names don't exist, the code would throw a SQLException at runtime.

Option D is correct as it uses the proper column name.




PreviousNext

Related