This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Retrieving Count (*) value

 
Param Yanamandra
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,
Here is my problem. I have a table and I m interested in finding the number of rows from a select statement.
SELECT COUNT(EMPID) FROM EMPLOYEE WHERE DEPARTMENT = 'HR';
After I execute the query I don't know how to retrieve the integer value. I used ResultSet.getInt(integer) but it doesn't help. Any idea on how to get the count value. Appreciate your response. Thanks,
Param
 
Param Yanamandra
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I figured it out. ResultSet.getInt(1) since the result set has only one column containing the Count(Empid) value.
 
Aamir Iqbal
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u can use
resultset.getInt("COUNT(EMPID)")
or
resultset.getInt(1); according to your query
 
Aamir Iqbal
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u can use
resultset.getInt("COUNT(EMPID)")
or
resultset.getInt(1); according to your query
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!