分享

ResultSet对象关闭

 timein 2014-03-26

今天实验室一个同学利用同一个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.

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多