• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java report data grouping

 
Jason Eilert
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jason Eilert
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all very much, this helped me out.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic