ResultSet对象关闭

今天实验室一个同学利用同一个Statement对象调用executeQuery方法分别执行不同的SQL查询语句,结果第一次调用返回的ResultSet对象在后面不再可用,提示该对象已经关闭无法执行其他的操作。答案在JDBC4.0规范里面得到了解释:

A ResultSet object is explicitly closed when(ResultSet对象显示关闭的两种情况:)
■ The close method on the ResultSet is executed, thereby releasing any external resources
■ The Statement or Connection object that produced the ResultSet is explictly closed


A ResultSet object is implicitly closed when(隐式关闭的两种情况:)
■ The associated Statement object is re-executed(相关Statement对象重新执行了操作则上一次的ResultSet对象会隐式的关闭)
■ The ResultSet is created with a Holdability of CLOSE_CURSORS_AT_COMMIT and an implicit or explicit commit occurs


Note – Some JDBC driver implementations may also implicitly close the ResultSet when the ResultSet type is TYPE_FORWARD_ONLY and the next method of ResultSet returns false.
Once a ResultSet has been closed, any attempt to access any of its methods with the exception of the isClosed or close methods will result in a SQLException being thrown. ResultSetMetaData instances that were created by a ResultSet that has been closed are still accessible.138 JDBC 4.0 Specification • November 2006


Note – The closing of a ResultSet object does not close the Blob, Clob, NClob or SQLXML objects created by the ResultSet. Blob, Clob, NClob and SQLXML objects remain valid for at least the duration of the transation in which they are created, unless their free method is invoked.

你可能感兴趣的:(sql,jdbc,Access)