Bug #113127 Execution of executeUpdate Closes Previously Acquired ResultSet
Submitted: 18 Nov 2023 8:11 Modified: 14 Jan 17:06
Reporter: Wenqian Deng Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:8.1.0 OS:Any
Assigned to: CPU Architecture:Any

[18 Nov 2023 8:11] Wenqian Deng
Description:
The execution of an executeUpdate statement unexpectedly leads to the closure of a previously obtained ResultSet object.
In the provided test case, a ResultSet object is obtained by calling getGeneratedKeys() on a Statement object after executing an UPDATE statement. This ResultSet is expected to remain open for subsequent operations. However, when another executeUpdate is executed on the same Statement object, the previously obtained ResultSet is found to be closed.
The expected behavior is that executing an executeUpdate statement should not affect the state (open or closed) of a previously acquired ResultSet.

How to repeat:
@Test
public void test() throws SQLException {
    Connection con;
    Statement stmt;
    ResultSet rs;
    con = DriverManager.getConnection("jdbc:mysql://localhost:3366/test16?user=user&password=password");
    stmt = con.createStatement(1003, 1008, 2);
    stmt.executeUpdate("CREATE TABLE table16_0(id REAL PRIMARY KEY,value INT);");
    stmt.executeUpdate("UPDATE table16_0 SET value = 77 WHERE id <= 1", 1);
    stmt.executeBatch();
    rs = stmt.getGeneratedKeys();
    System.out.println(rs.isClosed()); // false
    stmt.executeUpdate("DELETE FROM table16_0 WHERE id <= 2055473207", 1);
    System.out.println(rs.isClosed()); // true
    con.close();
}
[24 Nov 2023 6:13] MySQL Verification Team
Hello Wenqian Deng,

Thank you for the report and test case.
Verified as described.

regards,
Umesh
[14 Dec 2023 17:05] Axyoan Marcelo
Posted by developer:
 
According to the ResultSet documentation https://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html

"A ResultSet object is automatically closed when the Statement object that generated it is closed, re-executed, or used to retrieve the next result from a sequence of multiple results."

The ResultSet closing is thus the expected behavior, as the Statement that generated it was re-executed
[15 Jan 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".