How to avoid OOM (Out of memory) error when retrieving all records from huge table? How to avoid OOM (Out of memory) error when retrieving all records from huge table? sql sql

How to avoid OOM (Out of memory) error when retrieving all records from huge table?


With a little more information I can get a more helpful answer.

If you are using MySQL:

stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,       java.sql.ResultSet.CONCUR_READ_ONLY);stmt.setFetchSize(Integer.MIN_VALUE);

from http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.html:

java.util.Properties info = new java.util.Properties();info.put ("user", "scott");info.put ("password","tiger");info.put ("defaultRowPrefetch","15");getConnection ("jdbc:oracle:oci:@",info);


I think you could use the same solution as this one. A scrollable resultset.


If you are using JDBC you can use a ResultSet with a cursor which you iterate through one record at a time. You need to makes sure then that you write your XML out to a file one record at a time rather than using DOM to build the XML.