jdbc操作数据库中遇到ResultSet关闭的问题

以前的一个项目用jdbc操作数据库,事务方面未做好。最近出现了许多问题,所以对它进行修改。
只好采用最原始的connection.setAutoCommit(false);来设置事务,由于业务逻辑过于复杂,这个方法写了381行。当中涉及到许多增删改查操作,其中用到了多个ResultSet。经过测试发现,当出现多个ResultSet时经常会报错说ResultSet已关闭。
在网上查了一下,是由于一个Statement操作获得多个ResultSet时就会产生这种错误。这种情况下只需要多创建几个Statement,当需要多个ResultSet时分别用多个Statement执行就不会报错了。
我只写了解决方法,至于为什么会这样,具体原因我也不太了解。
查到的原因如下:
the object used for executing a static sql statement and returning the results it produces. by default, only one resultset object per statement object can be open at the same time. therefore, if the reading of one resultset object is interleaved with the reading of another, each must have been generated by different statement objects. all execution methods in the statement interface implicitly close a statments current resultset object if an open one exists.

原文地址:http://www.sudu.cn/info/html/edu/java/20071225/19718.html
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值