How do you access the value of an SQL count () query in a Java program How do you access the value of an SQL count () query in a Java program sql sql

How do you access the value of an SQL count () query in a Java program


Use aliases:

SELECT COUNT(*) AS total FROM ..

and then

rs3.getInt("total")


The answers provided by Bohzo and Brabster will obviously work, but you could also just use:

rs3.getInt(1);

to get the value in the first, and in your case, only column.


I would expect this query to work with your program:

"SELECT COUNT(*) AS count FROM "+lastTempTable+")"

(You need to alias the column, not the table)