To create a ResultSet object, you can use executeQuery methods, or other methods. This article describes options for creating ResultSets.
These methods are from the Statement, PreparedStatement, or CallableStatement interfaces. There are, however, other available methods. For example, DatabaseMetaData methods such as getColumns, getTables, getUDTs, getPrimaryKeys, and so on, return ResultSets. It is also possible to have a single SQL statement return multiple ResultSets for processing. You can also use the getResultSet method to retrieve a ResultSet object after calling the execute method provided by the Statement, PreparedStatement, or CallableStatement interfaces.
See Example: Create a procedure with multiple ResultSets for more information.
While a ResultSet object is automatically closed when the Statement object with which it is associated closes, it is recommended that you close ResultSet objects when you are finished using them. By doing so, you immediately free internal database resources that can increase application throughput.
It is also important to close ResultSets generated by DatabaseMetaData calls. Because you do not directly have access to the Statement object that was used to create these ResultSets, you do not call close on the Statement object directly. These objects are linked together in such a way that the JDBC driver closes the internal Statement object when you close the external ResultSet object. When these objects are not closed manually, the system continues to work; however, it uses more resources than is necessary.