This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Diaplaying a sum 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 "Diaplaying a sum" Watch "Diaplaying a sum" New topic

Diaplaying a sum

Frank Black

Joined: Mar 31, 2004
Posts: 10
I have a query on an excel spreadsheet that shows something like the following;
String sql = "select a.manager, sum(qty) "+
"from [db1$] a " +
" ,[db2$] b " +
"where a.dept = b.dept "
"and a.manager = b.manager " +
"group by a.manager ";

Statement s = conn.createStatement();
ResultSet rs = s.executeQuery(sql);
while (
System.out.print(" ");


To display the data I wanted to do the following;
Frank Black

Joined: Mar 31, 2004
Posts: 10
Sorry, hit enter to quickly!

Basically I want to know how to display my sum(qty) data?
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32481

You have two choices:

1) rs.getInt(2);

2) String sql = "select a.manager, sum(qty) as total ";

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Frank Black

Joined: Mar 31, 2004
Posts: 10
Thanks Jeanne!
I agree. Here's the link:
subject: Diaplaying a sum
It's not a secret anymore!