File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes How to do groupby in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to do groupby in java" Watch "How to do groupby in java" New topic

How to do groupby in java

Vasudevan Gopalan
Ranch Hand

Joined: Aug 29, 2003
Posts: 67
I am getting records from database like this in a while loop

I need to get the sum of second column grouped by empid .I can achieve this by giving group by clause in sql query but i cant give group by clause in query since the query is a union query .How can we group the records using java .My desired output for above query is

Is there any Util class for group by?.

Alex Leung

Joined: Dec 08, 2003
Posts: 26
I have not touch JDBC for a while now, but what I know is you have to execute the SQL statement on the database itself from java then retrieve the data into the program, using java.sql
so you need to execute something like this on the database inside java:
SELECT EmpId, COUNT(*) AS some_column
FROM table_name
hope this helps.
I agree. Here's the link:
subject: How to do groupby in java
It's not a secret anymore!