Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.NClob;
Expand Down Expand Up @@ -1882,6 +1883,31 @@ public void testExceptionOnClosedResultSet() throws Exception {
});
}

/**
* Tests that metadata result sets, which are created without an associated statement (stmt == null),
* report a usable (not closed) state, in line with {@link ResultSet#isClosed()} semantics.
*
* @throws Exception If failed.
*/
@Test
public void testMetadataResultSetIsClosed() throws Exception {
DatabaseMetaData meta = stmt.getConnection().getMetaData();

ResultSet rs = meta.getTables(null, null, "%", null);

// Metadata result sets are created without a statement and must be usable, not reported as closed.
assertFalse("Metadata result set must not be reported as closed", rs.isClosed());

// The result set must be iterable/usable.
while (rs.next())
rs.getString("TABLE_NAME");

// Explicitly closing the metadata result set must mark it as closed.
rs.close();

assertTrue("Explicitly closed metadata result set must be reported as closed", rs.isClosed());
}

/**
* Test object.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ else if (cls == String.class || cls == Character.class) {

/** {@inheritDoc} */
@Override public boolean isClosed() throws SQLException {
return closed || stmt == null || stmt.connection().isClosed();
return closed || (stmt != null && stmt.connection().isClosed());
}

/** {@inheritDoc} */
Expand Down