• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Diaplaying a sum

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, hit enter to quickly!

Basically I want to know how to display my sum(qty) data?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jeanne!
 
reply
    Bookmark Topic Watch Topic
  • New Topic