Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6760277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:02:48+00:00 2026-05-26T14:02:48+00:00

I have a method to get a load of objects from a database, which

  • 0

I have a method to get a load of objects from a database, which returns an Iterable.

For now, I am loading a resultset from a database, building objects from it and populating a collection with those objects.

Obviously, I’m memory constrained as to how much data can be loaded using this method and if I run out Bad Things Happen.

I’d like to modify the implementation to chunk data from the database instead of getting it all at once and then expose the resulting objects to the client through the Iterable interface. My database drivers can do their bit, so my first thought is a custom implementation of Iterable that does this.

Is this a good approach? It strikes me as something that might already be supported in the runtime or libraries – not involving ORM solutions please.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:02:48+00:00Added an answer on May 26, 2026 at 2:02 pm

    Personally the simplest solution that I can think of is to implement a Iterator as a thin wrapper around a ResultSet. That has several advantages:

    • You don’t need to provide reproducable SQL statements (you can stream non-sorted results, for example)
    • You don’t need to rely on repeatable read, which can be costly
    • If your JDBC driver is good, then you can just use its streaming result features (warning: some JDBC drivers always grab the full result as soon as you start iterating over it!)
    • You don’t need to implement re-starting the Iterator (Iterable.iterator() could be called twice, which makes this complicated).
    • Not “remembering” previously returned data means that the memory requirement can be held pretty low

    It also has a few disadvantages:

    • your Iterator implementation effectively becomes an external resources, since it binds a JDBC resource: it must be “closed” in some way, making it harder to use
    • if the Iterator hangs around for a longer time, then that also lets a JDBC Connection hang around, which might be needed elsewhere (you can’t return it to the pool, until the Iterator is done).

    An alternative way is to implement a List (or Collection) that lazily restores fractions of its data as needed. This can be nicer to use, but is quite a lot more complicated to build (correctly!). Also, if memory constraints are important, then you’ll need to add a mechanism to discard previously-restored objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base class with a property which (the get method) I want
I have created a Webpage which will post as post method..not as get method.
Hi I have a search results page which returns queries form the database using
In the following code, i have a method to get a Vector of persons
I have a get method passing in an object of type Store to the
I have a written a method to get all the records and return in
I have a method which calls for a classmethod of another class def get_interface_params_by_mac(self,
If I have a method such as: private function testMethod(param:string):void { // Get the
I have a program that makes use of the following method to get a
I have an application (ASP.NET MVC) that uses a Next New method to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.