This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread 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 Murach's Java Servlets and JSP this week in the Servlets 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: 30085
    
149

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get total records
 
Similar Threads
Should I add a Thread.yield() ?
maxCount value
The fizz buzz coding challenge
accesing database???
maximum no. of connections