What is the accurate ordering of resource closure when establishing a database connection through JDBC among the provided options?
* Connection, ResultSet, PreparedStatement
* PreparedStatement, ResultSet, Connection
* ResultSet, PreparedStatement, Connection
* ResultSet, Connection, PreparedStatement
* Connection, PreparedStatement, ResultSet
#java #certificationquestion #ocp
The correct ordering of resource closure when establishing a database connection through JDBC is:
ResultSet, PreparedStatement, Connection
This sequence ensures that resources are closed in the reverse order of their acquisition, releasing them from the innermost to the outermost, and avoiding any issues related to resource dependencies.
Establishing a Connection
https://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html
Interface ResultSet
A table of data representing a database result set, which is usually generated by executing a statement that queries the database.
https://docs.oracle.com/en/java/javase/17/docs/api/java.sql/java/sql/ResultSet.html
Interface PreparedStatement
An object that represents a precompiled SQL statement.
https://docs.oracle.com/en/java/javase/17/docs/api/java.sql/java/sql/PreparedStatement.html
Interface Connection
A connection (session) with a specific database. SQL statements are executed and results are returned within the context of a connection.
https://docs.oracle.com/en/java/javase/17/docs/api/java.sql/java/sql/Connection.html