fetchsize in resultset set to 0 by default

后端 未结 3 658
無奈伤痛
無奈伤痛 2021-01-14 17:37

I have to query a database and result set is very big. I am using MySQL as data base. To avoid the \"OutOfMemoryError\" after a lot of search I got two options:

3条回答
  •  星月不相逢
    2021-01-14 18:14

    Besides all you should change your query like

    SELECT * FROM RandomStones LIMIT 1000;
    

    Or

    PreparedStatement stmt = connection.prepareStatement(qry);
    stmt.setFetchSize(1000);
    stmt.executeQuery();
    

    To set the fetch size for a query, call setFetchSize() on the statement object prior to executing the query. If you set the fetch size to N, then N rows are fetched with each trip to the database.

提交回复
热议问题