+2  A: 

You can have a look at Jasper Reports:

http://www.docstoc.com/docs/2139263/Jasper-Report-Tutorial

or

http://www.javaworld.com/javaworld/jw-09-2002/jw-0920-opensourceprofile.html

It's a smart framework to generate reports.

Cristian Boariu
Thanks for responding, as for as report generation is concerned, I am fine with the option of using Jasper Reports. I have added more information regarding an optimized mechanism to construct the data in each row, if the number of variable parameters is huge.
Joshua
+1  A: 

You didn't give any details about the database back end you will be using, but in general the most efficient way to generate this information will be to process the data aggregation and filtering on the database side with the correct SQL and pass only the result set to your report generator. For the first example, which appears to be an aggregation of all of the data in the table, the database engine will have to sort and process all of the rows, but you'll be better off doing it there instead of the client. For queries involving subsets of the data, make sure you're indexed correctly for your queries.

cRob