It's not a secret anymore!*
The moose likes JDBC and the fly likes Retrieving Count (*) value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Retrieving Count (*) value" Watch "Retrieving Count (*) value" New topic
Author

Retrieving Count (*) value

Param Yanamandra
Ranch Hand

Joined: Jun 06, 2002
Posts: 33
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

Joined: Jun 06, 2002
Posts: 33
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

Joined: Nov 29, 2002
Posts: 17
u can use
resultset.getInt("COUNT(EMPID)")
or
resultset.getInt(1); according to your query
Aamir Iqbal
Greenhorn

Joined: Nov 29, 2002
Posts: 17
u can use
resultset.getInt("COUNT(EMPID)")
or
resultset.getInt(1); according to your query
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieving Count (*) value
 
Similar Threads
Translate int returned by hql(select .class) to Class<?>
Values not retireved using rownum in oracle
how to count active sessions in Servlet 2.2 specification
EJB-QL count query????
IBATIS - PROCEDURE -RESULT SET - OUT PARAM