I have table with 20+ millions of rows and I can't select all rows using single query because of OutOfMemoryError
. I read about fetchSize
attribute and looks like it might help to resolve my issue because it is common advise
But I have question about how to apply it.
I have following code:
private final JdbcTemplate jdbcTemplate;
...
jdbcTemplate.setFetchSize(1000);
List<MyTable> myList= this.jdbcTemplate.query(
"SELECT * FROM my_table",
new Object[]{},
MyTableMapper.INSTANCE
);
mylist.foreach(obj->processAndSave(obj));
Looks like jdbc driver will select 1000 per request. But what should I do to proceess all 20+ millions rows ?
Should I invoke jdbcTemplate.query
several times ?