aspose file tools
The moose likes JDBC and the fly likes How to do group by in a jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply 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: 13
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
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2692
    
    3

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 (Download) - the free mock exam kit for SCJP / OCPJP
Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56200
    
  13

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.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to do group by in a jsp
 
Similar Threads
Subselect joins
Getting the TD value using JavaScript + TD does not contain any ID.
what to do, if I get error `breaking on JScript rumtime error - object expected
Forms and values
Regular Expression test failure