1z0-809 Exam QuestionsBrowse all questions from this exam

1z0-809 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?

Show Answer
Correct Answer: BD

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

7 comments
Sign in to comment
jduarteOption: D
Feb 6, 2021

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

HuimOption: B
May 15, 2021

Answer is B. Prints nothing.

HuimOption: B
May 20, 2021

Answer ist B.

steefaandOption: B
Feb 7, 2024

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

iSnoverOption: D
Feb 9, 2024

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

shivkumarxOption: B
Apr 20, 2024

Answer is B, no exception was thrown

DarGrinOption: B
Jun 6, 2024

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