File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes ResultSet and sum Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "ResultSet and sum" Watch "ResultSet and sum" New topic
Author

ResultSet and sum

Ken Januski
Ranch Hand

Joined: Aug 08, 2002
Posts: 130
Hi,

I'm fairly new to JDBC and am trying to figure out if it's possible to use the results of sum(xxxx) in a ResultSet. I'm querying for "select sum(xxx) where xxx.....". But I can't figure out what to use to get the value of sum(). Can anyone tell me if this is possible?

Thanks,

Ken Januski
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56191
    
  13

It will be the only column returned, so:


int result = resultSet.getInt( 1 );


(assuming it's an int).

You could also assign an alias to the column and get that:


SELECT SUM(xxx) AS result WHERE ...

int result = resultSet.getInt( "result" );


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Ken Januski
Ranch Hand

Joined: Aug 08, 2002
Posts: 130
Thanks much Bear,

I think I had a fundamental misunderstanding of ResultSet that thought each ResultSet.getXXX() referred to the columns in actual database not in the ResultSet, though this goes against all logic:-).

I think that either of your solutions should do the trick.

Ken
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResultSet and sum
 
Similar Threads
Timer
Getting data from database into a collection
who can my question about this code
addAll
The BarTenders Kids