Streaming Large Result Sets with MySQL
When dealing with extensive MySQL tables within a Spring application, an OutOfMemoryException can arise as the driver endeavors to load the entire table into memory. Setting statement.setFetchSize(Integer.MIN_VALUE); may not suffice, as this merely provides a hint to the JDBC driver.
To enable streaming of result sets in the MySQL JDBC driver, a more comprehensive approach is required:
Create a Statement Instance:
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
Set the Fetch Size:
stmt.setFetchSize(Integer.MIN_VALUE);
Cautions:
This method has certain caveats:
Additional Insight:
For further strategies on handling large result sets, consider this related question and its answer: [link to similar question].
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3