如何在Java程序中访问SQL count()查询的值 [英] How do you access the value of an SQL count () query in a Java program
本文介绍了如何在Java程序中访问SQL count()查询的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想得到我使用SQL的COUNT命令找到的值。通常我输入我想访问getInt()getString()方法的列名,当没有特定的列名时,我该怎么做。
I want to get to the value I am finding using the COUNT command of SQL. Normally I enter the column name I want to access into the getInt() getString() method, what do I do in this case when there is no specific column name.
我使用'AS'与用于别名表的方式相同,我不知道这是否会工作,我不认为。
I have used 'AS' in the same manner as is used to alias a table, I am not sure if this is going to work, I would think not.
Statement stmt3 = con.createStatement();
ResultSet rs3 = stmt3.executeQuery("SELECT COUNT(*) FROM "+lastTempTable+") AS count");
while(rs3.next()){
count = rs3.getInt("count");
}
推荐答案
使用别名:
SELECT COUNT(*) AS total FROM ..
然后
rs3.getInt("total")
这篇关于如何在Java程序中访问SQL count()查询的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文