怎样判断数据库中有没有记录?

doskeym 2003-03-25 08:46:18
select * from tables where id=*

实现当*不存在时报错
...全文
32 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
freeever 2003-03-28
  • 打赏
  • 举报
回复
try {
while (rs.next()) {
ResultSet rs=st.executeQuery(sqlStr);
.....
}
} catch {
...
}
doskeym 2003-03-28
  • 打赏
  • 举报
回复
啊,我的意思是判断是否查找到了记录的结尾或开头
AllError 2003-03-27
  • 打赏
  • 举报
回复
select count(*) num from table

n=rs.getInteger("num")
n等于0时没有记录
:)
canyang 2003-03-27
  • 打赏
  • 举报
回复
String sqlStr="select * from tables where id=*";
不如这样写。
String sqlStr="select * from tables";
本来就是查询所有记录,又何必加个where条件呢?
foregump 2003-03-27
  • 打赏
  • 举报
回复
Statement stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);//设置记录集可以回滚
ResultSet rs=st.executeQuery(sqlStr);


if(rs1.next()) {//判定记录集是否为空


rs1.beforeFirst();//记录集回滚

while(rs1.next()){
数据库其他操作

}
}
很传统的记录集判定是否为空的方法。应该可以帮你解决问题的,祝你好运,盼你笑脸。~!@
xiaogangliang 2003-03-26
  • 打赏
  • 举报
回复
你试试这个:

String sqlStr="select * from tables where id=*";
ResultSet rs=st.executeQuery(sqlStr);
if(!rs.next())
{
out.println("没有记录");
}
hanty 2003-03-26
  • 打赏
  • 举报
回复
String sqlStr="select * from tables where id=*";
ResultSet rs=st.executeQuery(sqlStr);
if(rs.next())
{
out.println("没有记录");
}
这个写法有问题的
ginflzz 2003-03-26
  • 打赏
  • 举报
回复
if(!rs.next())
doskeym 2003-03-26
  • 打赏
  • 举报
回复
really??
suasalito 2003-03-25
  • 打赏
  • 举报
回复
String sqlStr="select * from tables where id=*";
ResultSet rs=st.executeQuery(sqlStr);
if(rs.next())
{
out.println("没有记录");
}

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧