Java OCA OCP Practice Question 2496

Question

Given the following table

id          INT PRIMARY KEY,
title       CHAR(100),
publisher   CHAR(100),
unit_price  REAL,

what is the result of the following code?

public class Main {
    public static void main(String[] args) throws SQLException{
        Connection con = null;/*from www .  j  a v  a 2s. c o  m*/
        try {
            con = getConnection();     //assume this get a valid connection
            con.setAutoCommit(false);
            Savepoint sv1 = con.setSavepoint();                 // line 1
            Statement statement = con.createStatement();
            statement.executeUpdate("UPDATE book " +
                                    "SET unit_price = 10.0");
            Savepoint sv2 = con.setSavepoint("sv2");            // line 2
            statement.executeUpdate("UPDATE book " +
                                    "SET unit_price = 20.0");
            con.rollback();
            con.commit();                                      // line 3
        }
        catch (SQLException e) {
            con.rollback();                                    // line 4
        }
    }
}
  • a The code updates the unit_price of all rows in table book to 10.0.
  • b The code updates the unit_price of all rows in table book to 20.0.
  • c There is no change in the value of unit_price in table book.
  • d The code fails to compile on either line 1, line 2, or line 4.
  • e If the code on line 3 throws a runtime exception other than SQLException, the code will update the unit_price of all rows in table book to 20.0.


c

Note

The code sets multiple save points.

The first, Save point-sv1, isn't tagged with a name.

When rollback() is called on a Connection object without the save point name, it's rolled back to the unnamed savepoint.




PreviousNext

Related