Bug #113129 setting the FetchSize on a Statement object does not affect
Submitted: 18 Nov 2023 10:28 Modified: 8 Apr 22:53
Reporter: Wenqian Deng Email Updates:
Status: Closed 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 10:28] Wenqian Deng
Description:
In the provided test case, the fetch size is set to 20 on a Statement object using stmt.setFetchSize(20). However, when a ResultSet is obtained from executing a query with this statement, the fetch size reported by the ResultSet (rs.getFetchSize()) is 0, indicating that the fetch size set on the Statement was not applied to the ResultSet.

The expected behavior is that the fetch size set on a Statement should be reflected in the ResultSet obtained from that statement. I also tried this test case on MariaDB connector and it changes the result set's fetch size.

How to repeat:
@Test
public void test() throws SQLException {
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;
        con = DriverManager.getConnection("jdbc:mysql://localhost:3366/test24", "user", "password");
        stmt = con.createStatement();
        stmt.setFetchSize(20);
        System.out.println(stmt.getFetchSize()); // 20
        rs = stmt.executeQuery("SELECT 1");
        System.out.println(rs.getFetchSize()); // 0
}
[24 Nov 2023 6:53] MySQL Verification Team
Hello Wenqian Deng,

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

regards,
Umesh
[8 Apr 22:53] Daniel So
Posted by developer:
 
Added the following entry to the Connector/J 8.4.0 changelog: 

"The FetchSize of the ResultSet returned by the execution of a Statement was not always the same as the value set on the Statement before using setFetchSize()."