简体   繁体   English

对未闭合的PreparedStatements / ResultSets / Connections进行IntelliJ检查

[英]IntelliJ inspections for unclosed PreparedStatements/ResultSets/Connections

Are there any IntelliJ inspections for unclosed PreparedStatements/ResultSets/Connections or anything using the standard Java SQL libraries? 对于未封闭的PreparedStatements / ResultSets / Connections或使用标准Java SQL库的任何内容,是否有任何IntelliJ检查?

I have to work with a relatively old Java codebase that uses a lot of SQL that isn't wrapped in a framework, so remembering all the special closing logic in the finally blocks for even very small bits of SQL can become tiresome and error-prone. 我必须使用一个相对较旧的Java代码库,该代码库使用大量未包含在框架中的SQL,所以记住finally块中的所有特殊结束逻辑即使是非常小的SQL也会变得令人厌烦且容易出错。

Be sure to turn on the following inspection: Settings > Editor > Inspections > Java > Resource management issues > "JDBC resource opened but not safely closed" 请务必打开以下检查: 设置>编辑器>检查> Java>资源管理问题>“JDBC资源已打开但未安全关闭”

Reports any JDBC resource which is not safely closed in a finally block. 报告在finally块中未安全关闭的任何JDBC资源。 Such resources may be inadvertently leaked if an exception is thrown before the resource is closed. 如果在资源关闭之前抛出异常,则可能无意中泄露此类资源。 JDBC resources reported by this inspection include java.sql.Connection, java.sql.Statement, java.sql.PreparedStatement, java.sql.CallableStatement, and java.sql.ResultSet. 此检查报告的JDBC资源包括java.sql.Connection,java.sql.Statement,java.sql.PreparedStatement,java.sql.CallableStatement和java.sql.ResultSet。

Please note that you can search the inspections list to find ones you need. 请注意,您可以搜索检查列表以查找所需的检查列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM