This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman 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

Win a copy of Elasticsearch in Action this week in the Big Data forum!
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: 31585

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]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, 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