Skip to content
Sharp

SQL for Java Devs · interview question

In JDBC, what should you do if an exception occurs after setting auto-commit to false and before committing?

Multiple choiceMediumchapter-8-curatedpremiumsql-for-java-devstransactions
Choose one answer
Answer and explanation

Correct answer

A. Call rollback()

Why

If an exception occurs after disabling auto-commit but before committing, you should call rollback() to revert any changes made during the transaction. This ensures data consistency by discarding partial updates.

Test yourself on SQL for Java Devs

A free test with instant, explained results. No account needed.

Start free test
All SQL for Java Devs questions →