This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes How to get total records Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to get total records" Watch "How to get total records" New topic
Author

How to get total records

Yogesh Dhond
Greenhorn

Joined: Jul 19, 2006
Posts: 17
Hi!!
I have a query as below in mysql
select count(*) as MAXCOUNT from table1;

how do i use this MAXCOUNT variable in my java program?
Masoud Kalali
Author
Ranch Hand

Joined: Jul 08, 2004
Posts: 531

what you mean in your java application ?
you can create a connection ,
create an statement,
execute the statement ,
get the result set ,
and first column in first row is your record count.

is it what you are looking for ?


Masoud Kalali
Software Engineer - My Weblog - GlassFish Security
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30356
    
150

Yogesh,
You have two choices:

1) rs.next();
int count = rs.getInt(1);

2) rs.next();
int count = rs.getInt("maxCount");


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

Joined: Jul 19, 2006
Posts: 17
Thank you very much!!
I got the required answer.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to get total records