What is the correct order to close database resources?

What is the correct order to close database resources?

A. Connection then Statement then ResultSet
B. ResultSet then Statement then Connection
C. Statement then Connection then ResultSet
D. Statement then ResultSet then Connection

Answer

B. ResultSet then Statement then Connection

Explanation:

When manually closing database resources, they should be closed in the reverse order from which they were opened. This means that the ResultSet object is closed before the Statement object and the Statement object is closed before the Connection object. This makes Option B the answer.

Comments