🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.It makes queries run faster
  2. B.It is required by the JDBC driver
  3. C.It closes the connection automatically, even when an exception is thrown
  4. 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 →