aspose file tools*
The moose likes JDBC 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
Bookmark "Diaplaying a sum" Watch "Diaplaying a sum" New topic
Author

Diaplaying a sum

Frank Black
Greenhorn

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 (rs.next())
{
System.out.print(rs.getString("manager"));
System.out.print(" ");


}


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

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30324
    
150

Frank,
You have two choices:

1) rs.getInt(2);

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


[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
Greenhorn

Joined: Mar 31, 2004
Posts: 10
Thanks Jeanne!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Diaplaying a sum