关于resultset

lllindada lllindada 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
有一个表onlineUser用于记录当前在线的人数,表中charRoom字段表示在线人所在的房间。
public int countUser(String chatRoom)
throws SQLException,ClassNotFoundException
{
BaseConn conn=null;
try
{
conn=new BaseConn();
String sql="select count(*) As intCount from onlineUser where chatRoom=?";
PreparedStatement ps=conn.preparedStatement(sql);
ps.setString(1,chatRoom);
ResultSet rs=conn.executeQuery();--这里rs里存的是一个数字还是一个集合?如果是集合的话包括哪个字段,只有intCount吗?如果表中没有记录,那么这个查询结果是什么?
if (rs.next())
return rs.getInt("intCount");
else
return 0;
}catch(SQLException ex)
{
ex.printStackTrace();
throw ex;
}catch(ClassNotFoundException ex)
{
ex.printStackTrace();
throw ex;
}finally
{
conn.close();
}
}
...全文

相关推荐

评论 12
收藏 已收藏
分享
返回顶部
lllindada
Web 开发 81,108 成员 341,721 内容