This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JDBC and the fly likes How to do group by in a jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to do group by in a jsp" Watch "How to do group by in a jsp" New topic
Author

How to do group by in a jsp

Omar Ali
Greenhorn

Joined: Dec 23, 2008
Posts: 15
Hello All,

I am having difficulties while doing the grouping in a jsp.

I am having a table which is retrieving the employee No., Directorate. The directorate name is coming duplicate as it is retrieved from the DB.
My jsp is displaying:
111 IT
222 IT
333 IT
So, I want it in the jsp as:
IT
111
222
333
Can you please help.
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2885
    
  13

This is not something you should do right in the JSP. You can make a list of employees for each directorate from somewhere in your business classes, and make your controller to set a request attribute carrying the list of directorates. Here, each directorate object should either contain or mapped to a list of corresponding employee objects. From the JSP, you can iterate over this directorates list using forEach tag of the JSTL core library. At each iteration, you can have another (nested) forEach iteration to iterate over the corresponding employee objects.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
My Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Move any Java code out of the JSP. Putting JSP code in modern JSP is a poor practice and downright irresponsible at this stage.

I've moved this to the JDBC forum because it's not about JSP.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to do group by in a jsp
 
Similar Threads
Forms and values
Subselect joins
Regular Expression test failure
what to do, if I get error `breaking on JScript rumtime error - object expected
Getting the TD value using JavaScript + TD does not contain any ID.