CloseResource Rule for Class level variable
A source code analyzer
Brought to you by:
adangel,
juansotuyo
I was working on the piece of code in which I created a class level reference variable for Connection. I instantiated this connection in main method in my class. When I check the code with PMD it does not ask or does not show any warning to close the connection.
public class myclass{
private Connection conn;
public static void main(String[] arg){
//..............
conn = DriverManager.getConnection(url,user,password);
//..............
}
}
The example provided cannot compile. Can you fix please, so we know 100% what you are referring to? Thanks.
PMDTest.java for example of above issue
Kindly find the attached file PMDTest.java. You need to change the database driver, url, username, password to connect elsewise also it will compile.
File Added: PMDTest.java