Does a ResultSet load all data into memory or only when requested?

前端 未结 5 820
眼角桃花
眼角桃花 2020-11-30 04:57

I have a .jsp page where I have a GUI table that displays records from an Oracle database. This table allows typical pagination behaviour, such as \"FIRST\", \"NEXT\", \"PRE

5条回答
  •  执念已碎
    2020-11-30 05:15

    The JDBC spec does not specify whether the data is streamed or if it is loaded into memory. Oracle streams by default. MySQL does not. To get MySQL to stream the resultset, you need to set the following on the Statement:

        pstmt = conn.prepareStatement(
            sql,
            ResultSet.TYPE_FORWARD_ONLY,
            ResultSet.CONCUR_READ_ONLY);
        pstmt.setFetchSize(Integer.MIN_VALUE);
    

提交回复
热议问题