"select count(主键) from 表名", 这句要用在Java时,怎么可以得到int的数值结果?

2025-04-04 08:29:15
推荐回答(3个)
回答1:

select count(userid) as countNum from tableName;
ResultSet rs=ps.executeQuery();
int nums=rs.getInt(0);

好像是这样,你可以试一下!

回答2:

int count=0;
PreparedStatement pstmt = conn.prepareStatement(sql);

ResultSet rs = pstmt.executeQuery();

rs.next();
count = rs.getInt(1);
return count;

回答3:

描述不清啊。