jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases 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
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "How to do group by in a jsp" Watch "How to do group by in a jsp" New topic

How to do group by in a jsp

Omar Ali
Ranch Hand

Joined: Dec 23, 2008
Posts: 33
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:
Can you please help.
Devaka Cooray
ExamLab Creator

Joined: Jul 29, 2008
Posts: 3921

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
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

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] [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
It's not a secret anymore!