Skip to content
Sharp

SQL for Java Devs · interview question

Why is it important to close a JDBC Connection, Statement, and ResultSet in a finally block or using try-with-resources?

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

Correct answer

A. To prevent memory leaks and ensure resources are freed

Why

Closing JDBC resources like Connection, Statement, and ResultSet is crucial to prevent memory leaks and ensure that database resources are freed. Using try-with-resources helps automate this process and keeps the code cleaner.

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 →