3

I'm trying to find a specific record. So what's better to do? Use a mysql statement to find the record or grab the whole table, put in a arraylist and iterate through it until I find what I want?

4

2 に答える 2

10

It is always better to offload database work to database.

Some of the advantages I see are:

You will get only the data you want, which improves performance, result will be faster (Most of database servers comes with optimization to improve query execution paths).

Save the space. You don't need to keep unwanted data in runtime memory

于 2012-09-02T18:13:55.673 に答える
1

I think making a Database query will be faster and efficient than taking all the data into ArrayList and then processing it...

MoreOver writing a logic will be hectic if that can be solved with one well prepared query to the database...

ArrayList is an object itself, and i think you will also need to store the datas in the DB as an Object of some custom made class... That will take space.....!!!

Sometime you may need only a small piece of info, consider just a value from a table... then i think using something like ArrayList is not a smart move....

于 2012-09-02T18:15:03.950 に答える