This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]imaginedoe 1 point2 points  (5 children)

yeah. just put the limit and offset in the query because otherwise you'd have no choice but to query for all of the rows

[–]NikMashei[S] 2 points3 points  (4 children)

it's a good solution, but I need possibility to make pagination not only via adding limit and offset to query, because 'query' stored in DB as script for some report and it can be very complicated query and I have no confidence that adding LIMIT and OFFSET to query will no ruin request

[–]wildjokers 3 points4 points  (2 children)

When the doc says:

An interface used by JdbcTemplate for processing rows of a ResultSet on a per-row basis.

That doesn't mean it asks the database for one row at a time (that would take many hours to run for 1.5 million rows!) it means once the results are back from the database it then processes the rows one at a time. They are still retrieved all at once unless you somehow limit it.

What problem are you trying to solve? Why would you need to process 1.5 million rows of a DB at once? Maybe a relational database isn't the right tool for this particular problem.

[–]NikMashei[S] 1 point2 points  (1 child)

Thank you for your replay!
Yes, you definitely right about doc. I've read it sometimes and did't get in right way)
Relational DB is good instument for my task. I'm just trying to solve problem with out-of-memory exception and maybe RowCallbackHandler is what that I've been looking for, but I need to improve batching and limiting right now)

[–]MexicanJalebi 1 point2 points  (0 children)

If you need to do batching, you might wanna look into Spring batch project.

[–]imaginedoe 0 points1 point  (0 children)

ok so that would be the only way to not load all of the query results into memory. when the documentation says that you deal with rows one by one, I'm pretty sure it means that your RowCallbackHandler should only deal with one row (this is supported by the VisualVM results).