Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 171

Given records from the Player table:

and given the code fragment: try {

Connection conn = DriverManager.getConnection(URL, username, password);

Statement st= conn.createStatement(

ResultSet.TYPE_SCROLL_SENSITIVE,

ResultSet.CONCUR_UPDATABLE);

st.execute ("SELECT * FROM Player");

st.setMaxRows(2);

ResultSet rs = st.getResultSet();

rs.absolute(3);

while (rs.next ()) {

System.out.println(rs.getInt(1) + " " + rs.getString(2));

}

} catch (SQLException ex) {

System.out.print("SQLException is thrown.");

}

Assume that:

The required database driver is configured in the classpath.

The appropriate database is accessible with URL, username, and password.

The SQL query is valid.

What is the result?

    Correct Answer: B

    The code sets the maximum number of rows for the result set to 2 using st.setMaxRows(2), which means the ResultSet will contain only the first two rows from the query, i.e., (1, Dave) and (2, Jack). The method rs.absolute(3) tries to move the cursor to the third row in the ResultSet. However, since the ResultSet contains only two rows, rs.absolute(3) will return false, indicating that the cursor is not positioned on a valid row. When rs.next() is called, it will move the cursor to the next row, which does not exist, so the while loop will not execute, and nothing will be printed. Therefore, the correct answer is that the program prints nothing.

Discussion
jduarteOption: D

Answer D. Tested. rs.absolute(3); move to the rows 3 and no exist

HuimOption: B

Answer ist B.

HuimOption: B

Answer is B. Prints nothing.

DarGrinOption: B

Answer is B. The program prints nothing. rs.absolute(3) moves the cursor to the 3.row. And then rs.next() moves the cursor to the 4.row, which does'n exist

shivkumarxOption: B

Answer is B, no exception was thrown

iSnoverOption: D

Answer D. Tested. rs.absolute(3); move to the rows 3 and no exist

steefaandOption: B

It should be B as rs.absolute(3) will just return false and it shouldn't throw exception.