← Quiz: JDBC: all 10 questions
Quiz: JDBC · Question 6 of 10
Why should a Connection be opened in try-with-resources?
Why should a Connection be opened in try-with-resources?
- A.It makes queries run faster
- B.It is required by the JDBC driver
- C.It closes the connection automatically, even when an exception is thrown
- D.It turns on auto-commit
Answer & explanation
Correct answer: It closes the connection automatically, even when an exception is thrown
Leaked connections are a classic production bug; try-with-resources prevents it.
Can you get the rest right without peeking?
Take the timed Quiz: JDBC quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →