Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get total records

 
Yogesh Dhond
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 531
Java Mac OS X Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34671
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yogesh,
You have two choices:

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

2) rs.next();
int count = rs.getInt("maxCount");
 
Yogesh Dhond
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much!!
I got the required answer.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic