if you have the 5000 records in memory then its best to deal with that
how you decide. if java is client side, then its not such an issue.
however, if you want to save server side load then its best to do
selects at the user's request, so;
select count['*'] from table;
now you know the number of records.
then paginate those records at the user's request. it is unlikely that
the user wants all 5000 records in 99% of cases, consider google's
paginated records, how many people will look at them all.