Are there any IntelliJ inspections for unclosed PreparedStatements/ResultSets/Connections or anything using the standard Java SQL libraries?
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.
Press Ctrl+Alt+S to open the IDE settings and select Tools | Actions on Save. Enable the Run code cleanup option. Additionally, you can click Configure inspections to specify the inspection profile from which the IDE will run code cleanup inspections.
From the main menu, select Code | Analyze Code | Dependencies. Alternatively, if you want to analyze a specific item, right-click it in the Project tool window and select Analyze | Analyze Dependencies. In the dialog that opens, specify the scope of files that you want to analyze.
Be sure to turn on the following inspection: Settings > Editor > Inspections > Java > Resource management issues > "JDBC resource opened but not safely closed"
Reports any JDBC resource which is not safely closed in a finally block. 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.
Please note that you can search the inspections list to find ones you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With