ResultSet问题

miguboy 2009-05-15 12:05:12

ResultSet rs1=stmt.executeQuery("select * from book where bno='"+bno+"'");
if(!rs1.next()){out.println("不存在图书编号为"+bno+"的图书");}

else {
if(select.equals("查询")){
ResultSet rs2=stmt.executeQuery("select * from book where bno='"+bno+"'");
我把rs1和rs2都改成rs1,但第二rs1显示为空,为什么?
...全文
105 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
miguboy 2009-05-18
  • 打赏
  • 举报
回复
谢谢 各位大哥 懂了
hjjk888 2009-05-16
  • 打赏
  • 举报
回复
执行一次!stmt会自动关闭!所以在调用就会出错!
wmm88257789 2009-05-16
  • 打赏
  • 举报
回复
在else里边直接引用rs1就ok了的 就像楼上说的不用写两句sql语句的
oklinsong 2009-05-15
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wanghao1987 的回复:]
把rs1和rs2都改成rs1,程序运行前,应当会给出编译错误吧
[/Quote]
同意,变量名重复吧!
wanghao1987 2009-05-15
  • 打赏
  • 举报
回复
把rs1和rs2都改成rs1,程序运行前,应当会给出编译错误吧
zdtwyjp 2009-05-15
  • 打赏
  • 举报
回复
有必要将一条SQL语句写两次嘛!
marcblue 2009-05-15
  • 打赏
  • 举报
回复
你把第2个ResultSet去掉,就rs1=stmt.executeQuery("select * from book where bno='"+bno+"'");
FlyingBird1986 2009-05-15
  • 打赏
  • 举报
回复
你的是不是有个传递参数(查询)的查询和一个没有传递参数的查询啊?你这样的代码让人有些模糊---

估计还是楼上的写到了家---
hli33 2009-05-15
  • 打赏
  • 举报
回复
ResultSet rs1=stmt.executeQuery("select * from book where bno='"+bno+"'");
if(!rs1.next()){
System.out.println("不存在图书编号为"+bno+"的图书");
stmt.close();
} else{
if(select.equals("查询")){

return rs1;
}
}
hli33 2009-05-15
  • 打赏
  • 举报
回复
为什么要写2遍 rs1=stmt.executeQuery("select * from book where bno='"+bno+"'");
marcblue 2009-05-15
  • 打赏
  • 举报
回复
ResultSet rs1=stmt.executeQuery("select * from book where bno='"+bno+"'");
if(!rs1.next()){
System.out.println("不存在图书编号为"+bno+"的图书");
stmt.close();
rst1=null;
}

else{
if(select.equals("查询")){

rs1=stmt.executeQuery("select * from book where bno='"+bno+"'");
}
}
sun403 2009-05-15
  • 打赏
  • 举报
回复
中间加上stmt.close();rst1=null;
然后再都改为rst1

81,092

社区成员

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

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