我是否需要显式调用数组、clob 等的free()
...或者关闭 ResultSet 和/或 Statement 会自动解决这个问题? javadoc 什么也没说,所以我认为没有必要,但我不想做出错误的假设。
此外,如果没有必要,立即关闭结果集是否是个好主意?如果您不打算这样做,我可以看到它会有什么帮助。
最佳答案
这取决于您使用的供应商和 JDBC 版本。由于所有数据库供应商都不支持数组(例如MySQL)
这可能就是 javadoc 什么也没说的原因。
我找到了这个教程 Using Array Object 在 oracle 站点的 JavaSE 教程中说要显式释放资源。
这是另一个链接,说明了 free()
的场景。
JDBC 4's java.sql.Clob.free() method and backwards compatibility
if its not necessary, is it a good idea if you're going to close the result set right away?
我认为不应该要求 free(),但是如果它是一个长时间运行的事务,那么调用 free() 也是好的。
引自tutorial :
Array objects remain valid for at least the duration of the transaction in which they are created. This could potentially result in an application running out of resources during a long running transaction. Applications may release Array resources by invoking their free method.
关于java - java.sql.Array/Blob/Clob 类型是否需要 "free()"ed?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12362726/