my dog learned polymorphism
The moose likes JDBC and Relational Databases and the fly likes Retrieving big list from that database and memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Retrieving big list from that database and memory" Watch "Retrieving big list from that database and memory" New topic

Retrieving big list from that database and memory

Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
How can I retrieve a big list from the database without consuming so much memory?
In my model, I use transfer objets to bring the data from the database to my application. Basically, I read every row from the ResultSet, then I encapsulate it into a corespondent object. But, what will happen if I have too many rows in the ResultSet? I will have to create too many objects, which will take too much memory.
Not: Also, I want to mentain a relationship to the acual record, for example: I want to retrieve all the the internet providers from the database, and display the name to the user, when the user click on the name, my DAO should retrieve the provider data and display it to the user. But if I have 1000 providers, I will have to create 1000 objects.
how can I solve this problem?
I am new to the database stuff, and any help is appreciated.

SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
I'm afraid there's no easy answer to this. You can try to tailor your SQL statement to return a smaller ResultSet. Barring this though, I'm afraid you're stuck. You could of course just read in primary key values and then read in the actual ones you need when you need them. That would incur more network traffic though. However, your memory footprint would be smaller.
I suppose you'll just have to weigh the options and your performance/memory needs.

I agree. Here's the link:
subject: Retrieving big list from that database and memory
It's not a secret anymore!