• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java report data grouping

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all very much, this helped me out.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic