Java OCA OCP Practice Question 2300

Question

Consider the following code snippet:


try(ResultSet resultSet = statement.executeQuery("SELECT * FROM contact")) {

        // Stmt #1

        resultSet.updateString("firstName", "John");
        resultSet.updateString("lastName", "K.");
        resultSet.updateString("email", "john@abc.com");
        resultSet.updateString("phoneNo", "+12345678901");

        // Stmt #2

        // rest of the code elided
}

assume that resultSet and statement are legitimate instances of the ResultSet and Statement interfaces, respectively.

which one of the following statements is correct with respect to stmt #1 and stmt #2 for successfully inserting a new row?.

A.  replacing stmt #1 with resultSet.moveToInsertRow() 
    will make the program work.//from   ww w. jav a 2s  .c  o m
    
B.  replacing stmt #1 with resultSet.insertRow() will 
    make the program work.
    
C.  replacing stmt #1 with resultSet.moveToInsertRow() and 
    stmt #2 with resultSet.insertRow() will make the program work.
    
d.  replacing stmt #1 with resultSet.insertRow() and stmt #2 
    with resultSet.moveToInsertRow() will make the program work.


C.

Note

You need to call the moveToInsertRow() method in order to insert a new row: this method prepares the resultset for creating a new row.

once the row is updated, you need to call insertRow() to insert the row into the resultset and the database.




PreviousNext

Related