Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

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.

like image 558
maschwenk Avatar asked Sep 02 '15 14:09

maschwenk


People also ask

How do I get rid of Intellij errors?

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.

Where is analyze in Intellij?

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.


1 Answers

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.

like image 85
Javaru Avatar answered Oct 07 '22 19:10

Javaru