| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4200 人关注过本帖
标题:求教一下java.sql.SQLException: ResultSet is closed问题该如何解决
只看楼主 加入收藏
antonio_jiao
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2007-7-6
收藏
得分:0 

好,我按照顶楼的语句执行,运行没有问题,实现完毕后会报出
java.sql.SQLException: ResultSet is closed

at sun.jdbc.odbc.JdbcOdbcResultSet.checkOpen(JdbcOdbcResultSet.java:6650)

at sun.jdbc.odbc.JdbcOdbcResultSet.next(JdbcOdbcResultSet.java:1251)

at exam2.BuyFrame.btnOk_actionPerformed(BuyFrame.java:107)

at exam2.BuyFrame_btnOk_actionAdapter.actionPerformed(BuyFrame.java:159)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Window.dispatchEventImpl(Window.java:1606)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

2007-07-28 12:07
antonio_jiao
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2007-7-6
收藏
得分:0 

当我把3个关闭写在finally后,也就是
catch (Exception ee) {
ee.printStackTrace();
}finally{
if (rs!= null) rs.close();
if (sm!= null) sm.close();
if (con!= null) con.close();
}
我加了以下语句,改了一下,但是报了新的错误,运行都通不过
"BuyFrame.java": variable rs might not have been initialized at line 147, column 17
"BuyFrame.java": variable rs might not have been initialized at line 148, column 17
"BuyFrame.java": variable rs might not have been initialized at line 149, column 17
"BuyFrame.java": unreported exception java.sql.SQLException; must be caught or declared to be thrown at line 147, column 36
"BuyFrame.java": unreported exception java.sql.SQLException; must be caught or declared to be thrown at line 148, column 36
"BuyFrame.java": unreported exception java.sql.SQLException; must be caught or declared to be thrown at line 149, column 36

也就是这3句话报错

2007-07-28 12:09
antonio_jiao
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2007-7-6
收藏
得分:0 
麻烦大家帮我看看,谢谢拉
2007-07-28 12:09
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
你应该重新生成一个Statement去执行新的语句

而不是用那个已经执行过的statement

sm.execute("update TrainTicket set seatNum="+result+" where TrainNo='"+No+"'");

这个sm已经被用过了,你应该重新生成过一个

可惜不是你,陪我到最后
2007-07-28 13:35
笑海
Rank: 5Rank: 5
等 级:贵宾
威 望:19
帖 子:4934
专家分:25
注 册:2007-4-29
收藏
得分:0 


这样啊

LZ在去试试

兔子不吃窝边草
2007-07-28 17:26
antonio_jiao
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2007-7-6
收藏
得分:0 
谢谢大家,我解决了,是由于脏读问题,重新定义一下sm,终于解决了
2007-07-29 19:36
快速回复:求教一下java.sql.SQLException: ResultSet is closed问题该如何解决
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025319 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved