Return to site

JAVA CERTIFICATION QUESTION: Using a Java ResultSet to view database tables

· java

Given the following WAREHOUSE table:

IDˑˑˑTITLEˑˑˑˑˑˑˑˑQUANTITY

——————————————————————————

0ˑˑˑˑCellˑPhoneˑˑˑ10

1ˑˑˑˑComputerˑˑˑˑˑ20

2ˑˑˑˑTVˑˑˑˑˑˑˑˑˑˑˑ30

And the following code fragment:

Connection conn = … // properly initialized connection
Statement stmt = conn.createStatement
(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet results = stmt.executeQuery("SELECT * FROM WAREHOUSE");
while (results.next()) {
    int id = results.getInt(1);
    if (id == 1) {
         results.updateInt(3, 15); // line n1 
         results.next();
         break;
    }
}
            
results.previous(); // line n2
int qty = results.getInt(3);
System.out.print(qty);

Assume the database connection is properly initialized, any JDBC features used are supported by the driver and database, and any modes not explicitly shown are default.

What is the result? Choose one.

A. Runtime exception at line n1

B. Runtime exception at line n2

C. 15

D. 20

·ꓷ uoᴉʇdo sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ ·uoᴉsnʅɔuoꓛ