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?
2 に答える
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
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....