Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 关闭的resultset异常
king_wjb





发贴: 27
积分: 0
于 2006-12-25 11:14 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我在程序中写了一段如下的代码:
conn = ConnectDB.getDBConnection();
      ps = conn.prepareStatement(strSql);
      rs = ps.executeQuery();
      while (rs.next()) {
        r_data.set_alarm_level_id(rs.getString("ID"));
        try {
          if (rs != null)
            rs.close();
          if (ps != null)
            ps.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
        ps = conn.prepareStatement(strSql2);
        rs = ps.executeQuery();
        while (rs.next()) {
          r_data.set_sound_alarm_level_id(rs.getString("ID"));
        }
      }

实际上strSql与strSql2都只有一条记录,结果在运行时经常会出现:关闭的resultset,无效的next()异常。请问应该如何解决?
(注,此段代码会定时周期执行,有时候出现异常,有时候没有)



作者 Re:关闭的resultset异常 [Re:king_wjb]
cxp108





发贴: 363
积分: 12
于 2006-12-25 11:35 user profilesend a private message to usersend email to cxp108search all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
如果数据库没有问题的话,很可能是你对conn,ps,rs这几个对象进行了多线程操作,其中有关闭的动作。


作者 Re:关闭的resultset异常 [Re:king_wjb]
king_wjb





发贴: 27
积分: 0
于 2006-12-25 11:43 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
但是为什么是偶尔出现呢


作者 Re:关闭的resultset异常 [Re:king_wjb]
cxp108





发贴: 363
积分: 12
于 2006-12-26 12:57 user profilesend a private message to usersend email to cxp108search all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
没看代码很难说....



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923