Currently I am using statement.executeQuery(qStr) in java to select a large amount of data from mysql. Unfortunatly, java keeps running out of memory at the statement.executeQuery(qStr) statement with exception java.lang.OutOfMemoryError: Java heap space. I am wondering if there is a method to stream load data from mysql. So that I can handle the selected data trunk by trunk to avoid running out of memory?
Note that: I am using eclipse and this post shows me how to increase the heap memory for java to use inside eclipse. But after I followed it’s method, i am still running into the same problem.
Thanks in advance.
Yes, you can set the FetchSize on a Statement to Integer.MIN_VALUE , the ResultSet should be
TYPE_FORWARD_ONLY as well, though I believe that’s the default.. MySQL treats that specially and enables streaming of the ResultSet instead of reading it all into memory, it’s documented here