File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "How to get total records" Watch "How to get total records" New topic

How to get total records

Yogesh Dhond

Joined: Jul 19, 2006
Posts: 17
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
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
author & internet detective

Joined: May 26, 2003
Posts: 33127

You have two choices:

int count = rs.getInt(1);

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

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Yogesh Dhond

Joined: Jul 19, 2006
Posts: 17
Thank you very much!!
I got the required answer.
I agree. Here's the link:
subject: How to get total records
It's not a secret anymore!