• Post Reply Bookmark Topic Watch Topic
  • New Topic

Diaplaying a sum

 
Frank Black
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 (rs.next())
{
System.out.print(rs.getString("manager"));
System.out.print(" ");


}


To display the data I wanted to do the following;
 
Frank Black
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, hit enter to quickly!

Basically I want to know how to display my sum(qty) data?
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36032
432
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frank,
You have two choices:

1) rs.getInt(2);

2) String sql = "select a.manager, sum(qty) as total ";
rs.getInt("total");
 
Frank Black
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne!
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!