I have a bean that handles all my database connections/queries and can't quite figure out how to get results from "SELECT count(*) FROM.." queries displayed on .jsp page.
Normally I use it like this:
and then request data with rs.getString("something")/rs.getInt("something) etc.
But how do I get the count when using "SELECT count(*) FROM"-statement ?
Joined: Sep 13, 2002
You still use the rs.getInt() method, but instead of passing in the column name, you use the column index. Since a SELECT count(*) query returns only a single column, the index is 1, like this: rs.getInt(1) [ June 10, 2004: Message edited by: Blake Minghelli ]
Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Peter den Haan
Joined: Apr 20, 2000
Alternatively, you give the column a name using an alias:
SELECT COUNT(*) AS COUNT FROM MYTABLE WHERE...
int count = rs.getInt("COUNT");
I assume that you know that embedding such database code in your JSP is bad practice... if you really need to, at least use the JSTL SQL tags.