Java OCA OCP Practice Question 3134

Question

Consider the following sequence of statements when using JDBC API. Assume that you've a TempSensor table with the column name temp.

// assume that connection is successfully established to the database
connection.setAutoCommit(true);/*from   w  w w  .j a  v  a 2s  .co m*/
Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
resultSet = statement.executeQuery("SELECT * FROM TempSensor");

// assume that the initial value of temp is "0" in the table

resultSet.moveToInsertRow();
resultSet.updateString("temp", "100");
resultSet.insertRow();
Savepoint firstSavepoint = connection.setSavepoint();

resultSet.moveToInsertRow();
resultSet.updateString("temp", "200");
resultSet.insertRow();
Savepoint secondSavepoint = connection.setSavepoint();

resultSet.moveToInsertRow();
resultSet.updateString("temp", "300");
resultSet.insertRow();
Savepoint thirdSavepoint = connection.setSavepoint();

connection.rollback(secondSavepoint);
connection.commit();

Which one of the following options correctly describes the behavior of this program?

a) temp value will be set to "100" in the table TempSensor.
b) temp value will be set to "200" in the table TempSensor.
c) temp value will be set to "300" in the table TempSensor.
d) temp value will be set to "0" in the table TempSensor.
e) The program will result in throwing a SQLException because auto-commit is true.


e)

Note

If you call methods such as commit() or rollback() when the auto-commit mode is set to true, the program will a SQLException.




PreviousNext

Related