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 } } }
c
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.