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

前端 未结 6 1410
甜味超标
甜味超标 2020-12-14 19:13

I am given a task to convert a huge table to custom XML file. I will be using Java for this job.

If I simply issue a \"SELECT * FROM customer\", it may return huge a

6条回答
  •  旧时难觅i
    2020-12-14 19:27

    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);
    

提交回复
热议问题