java.sql.SQLException:无效状态,ResultSet对象已关闭

编程入门 行业动态 更新时间:2024-10-21 05:56:27
本文介绍了java.sql.SQLException:无效状态,ResultSet对象已关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用jtds运行StoredProcedure. 我的数据库在SQL SErver 2008上

I am trying to run StoredProcedure using jtds. My database is on SQL SErver 2008

private String DRIVER_NAME_VALUE = "net.sourceforge.jtds.jdbc.Driver"; private String URL_VALUE = "jdbc:jtds:sqlserver://"; ... cstmt =dbConnection.getCallableStatement("{? = call dbo.GetAgentStats (?)}"); . . . rs = cstmt.executeQuery();

当尝试遍历结果集时,出现异常:

when trying to go over the Result set I got the Exception:

java.sql.SQLException: Invalid state, the ResultSet object is closed. at net.sourceforge.jtds.jdbc.JtdsResultSet.checkOpen(JtdsResultSet.java:299) at net.sourceforge.jtds.jdbc.JtdsResultSet.first(JtdsResultSet.java:527) at com.verint.impact360.WFM_plugins.CCE.CCEASCMAdapter.runReport(CCEASCMAdapter.java:238) at com.verint.impact360.WFM_plugins.CCE.CCEASCMAdapter.retrieveData(CCEASCMAdapter.java:131) at com.bluepumpkin.Plugins.PTeXtender.GenericDCSPlugin.retrieveStatisticsData(GenericDCSPlugin.java:332) at com.bluepumpkin.Plugins.PTeXtender.GenericDCSPlugin.start(GenericDCSPlugin.java:68) at com.verint.impact360.WFM_plugins.CCE.CCEASCMAdapter.main(CCEASCMAdapter.java:75) Logger.logStackTrace():----- End Stack Trace ------

它与SQL Server 2008有关吗? 我不确定,但是在连接到SQL Server 2005时没有出现此错误.

Is it related to SQL Server 2008? I am not sure ,but I didn't have this error when connectig to SQL Server 2005.

谢谢

推荐答案

仅当尚未关闭ResultSet时,可以通过在ResultSet,Statement和/或<上调用close()来遍历ResultSet c4>.

You can only iterate over the ResultSet when it has not already been closed by calling close() on ResultSet, Statement and/or Connection.

如果您的实际意图是将ResultSet的内容传递到创建它的方法的范围之外,则应首先将其映射到List<SomeObject>,然后将其返回.或者,如果您的实际意图是将其传递给其他需要ResultSet作为参数的类/方法(由于其本身的设计较差,但请注意),那么您应该在相同的块,因为创建了ResultSet.

If your actual intent is to pass the content of the ResultSet out of the scope of the method where it is been created, then you should be mapping this to a List<SomeObject> first and then return it instead. Or if your actual intent is to pass it to some other class/method which expects a ResultSet as argument (which is by its own a poor design, but that aside), then you should be doing that inside the very same try block as the ResultSet is been created.

更多推荐

java.sql.SQLException:无效状态,ResultSet对象已关闭

本文发布于:2023-10-18 10:58:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504038.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   状态   sql   java   ResultSet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!