• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Sybex CSG 17 - Chapter 15 - Review question 6

 
Greenhorn
Posts: 2
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe that there is a mistake in this review question. It reads as follows:

Suppose there are two rows in the table before this code is run, and executeUpdate() runs without error. How many rows are in the table after the code completes?

A. Two
B. Three
C. The code does not compile.
D. The code throws an exception.



The solution claims that the answer is:


B.  The first line enables autocommit mode. This is the default and means to commit immediately after each update. When the rollback() runs, there are no uncommitted statements, so there is nothing to roll back. This gives us the initial two rows in addition to the inserted one making option B correct. If setAutoCommit(false) were called, option A would be the answer. The ResultSet types are just there to mislead you. Any types are valid for executeUpdate() since no ResultSet is involved.



However, the documentation for Java SE 17's Connection::rollback https://docs.oracle.com/en/java/javase/17/docs/api/java.sql/java/sql/Connection.html#rollback() states that rollback throws an SQLException when


Throws:
SQLException - if a database access error occurs, this method is called while participating in a distributed transaction, this method is called on a closed connection or this Connection object is in auto-commit mode



As the Connection in the example is in auto-commit mode when rollback is called, any compliant implementation should throw an SQLException, meaning D should be the correct answer, no?

// EDIT: I checked the existing errata list, but not the forum history. I see that this was actually discussed in the context of one of the earlier books, where the (if you ask me, correct choice) decision was made to answer according to the javadoc api, and not some specific non-compliant) implementation.
https://coderanch.com/t/655693/certification/Calling-commit-rollback-autocommit-mode
 
author & internet detective
Posts: 42056
926
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a cow. This is now in the errata list.

The bigger problem is that this scenario isn't covered in the chapter or in scope for the exam.
 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic