java.sql.SQLException: Invalid state, the ResultSet object is closed

大憨熊 提交于 2020-01-25 02:45:07

问题


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   ------

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

Thanks


回答1:


You can only iterate over the ResultSet when it has not already been closed by calling close() on ResultSet, Statement and/or 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.



来源:https://stackoverflow.com/questions/4864920/java-sql-sqlexception-invalid-state-the-resultset-object-is-closed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!