Is it worth taking a count of the results in SQL, and then passing back two values from the jdbc call (count, result) so that I can determine the sizes and preallocate arrays instead of using arraylists to hold the contents of the results?
It seems like there's no way to win: either I spend more time in the db counting the rows, or spend time in the java app when using arraylists.
Note:
- My result set will have counts no more than, say, 100,000.
- results will have mostly integers or doubles (no strings).
- Preallocated arrays I assume are better because there's random access on these arrays later.
- The number of arrays is about 3-4 times the number of columns returned.
- These arrays will get accessed multiple times each.
- my program will be called multiple times as a service, so the cumulative overhead matters from the point of scalability both from the space as well as time perspective. That is another reason I'm trying to use arrays.
- I do not wish to start a debate on array vs. arraylists. I just wish to understand which of these will be more suitable in the context of my use.
Thanks.