aspose file tools
The moose likes JDBC and the fly likes java report data grouping Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "java report data grouping" Watch "java report data grouping" New topic
Author

java report data grouping

Jason Eilert
Greenhorn

Joined: May 22, 2006
Posts: 5
I have a question about data grouping in java. Suppose I wanted to group data from a query followed by detail records for that group. For example, if I have 2 tables (employee and department) and I wanted my data formatted as follows...

Department 10

George...(other employee info....)
Fred...(other employee info....)
Don...(other employee info....)
Frank...(other employee info....)

Department 30
John..(other employee info....)
Dan..(other employee info....)
Clyde...(other employee info....)

ect...

Is there an easy way to group data in this fasion in java after receiving from a query?

Thanks...
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
In your query, use an ORDER BY clause to order the ResultSet by department (and any secondary ordering you want, such as last name, first name).

In your Java, whenever the department changes, print (or whatever) a new department header, then start printing (or whatever) the row information for each employee.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1076

Alternatively you can also use HashMap or TreeMap to group your data.
In this case you will not require to use order by in query.

Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Jason Eilert
Greenhorn

Joined: May 22, 2006
Posts: 5
Thank you all very much, this helped me out.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java report data grouping
 
Similar Threads
SubQuery in Hibernate
Query -- select maximum salary in a sum table
Design question regarding managing one-to-many relationship...
Is this type of group by query possible in JPA ?
Joins in Hibernate