您好,我正在编写一个 java 代码,该代码旨在获取我正在处理的用户配置文件表中用户总数的计数。现在我确定我的 sql 语句是正确的,但由于某种原因,我不知道如何从中获取数值。非常感谢和欢迎任何帮助。我确信我试图获得价值的方式不起作用,但我不知道如何获得价值,下面是代码,谢谢:
public int getUserCount() throws SQLException {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
double encinfo;
conn = DAOFactory.getDatabaseDAO().getConnection();
StringBuffer query = new StringBuffer();
query.append( "Select COUNT (DISTINCT record_id)");
query.append( "From USER_PROFILE");
stmt = conn.createStatement();
rs = stmt.executeQuery( query.toString());
if (!rs.next())
throw new SQLException( SQLException.User_NOT_FOUND,"No User Count found.");
// Should be able to get the user amount or value or total users in DB.
userInfo = rs.getDouble( "USER_VALUE");
m_userCount = (int) userInfo;
}