Java OCA OCP Practice Question 2686

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", "+88888888888");
        //Stmt #2
 ...
}

Assume that resultSet and Statement are legitimate instances.

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() alone will make the program work.
b)Replacing Stmt #1 with resultSet.insertRow() alone 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 result set for creating a new row).

Once the row is updated, you need to call insertRow() to insert the row into result set and the database.




PreviousNext

Related