java.sql.SQLException: 无效状态,ResultSet 对象已关闭
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4864920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.sql.SQLException: Invalid state, the ResultSet object is closed
提问by Waseem
I am trying to run StoredProcedure using jtds. My database is on SQL SErver 2008
我正在尝试使用 jtds 运行 StoredProcedure。我的数据库在 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 ------
Is it related to SQL Server 2008? I am not sure ,but I didn't have this error when connectig to SQL Server 2005.
是否与 SQL Server 2008 有关?我不确定,但是在连接到 SQL Server 2005 时没有出现此错误。
Thanks
谢谢
回答by BalusC
You can only iterate over the ResultSet
when it has not already been closed by calling close()
on ResultSet
, Statement
and/or Connection
.
您只能遍历ResultSet
时,尚未通过调用封闭close()
的ResultSet
,Statement
和/或Connection
。
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.
如果您的实际意图是将 的内容传递到ResultSet
创建它的方法的范围之外,那么您应该List<SomeObject>
先将其映射到 a ,然后再返回它。或者,如果您的实际意图是将其传递给其他需要ResultSet
as 参数的类/方法(这本身就是一个糟糕的设计,但除此之外),那么您应该在与之前相同的try
块中执行此ResultSet
操作创建。