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

前端 未结 5 821
眼角桃花
眼角桃花 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:06

    lets say we have a table that contains 500 records in it

    PreparedStatement stm=con.prepareStatement("select * from table");
    stm.setFetchSize(100);// now each 100 records are loaded together from the database into the memory,
    // and since we have 500 5 server round trips will occur.
    ResultSet rs = stm.executeQuery();
    rs.setFetchSize (50);//overrides the fetch size provided in the statements,
    //and the next trip to the database will fetch the records based on the new fetch size
    

提交回复
热议问题