Severity | 2 |
---|---|
Enabled | yes |
Waivable | |
Violation |
public class MyDao { Statement global_stmt = null; ResultSet rs = null; public void select(){ Connection lcon_dbConnection = getConnection(); int i = 0; try{ global_stmt = lcon_dbConnection.createStatement(); rs = global_stmt.executeQuery("SELECT * FROM DUAL" ); } catch (Exception ex){ ex.printStackTrace(); } } |
Fix |
public class MyDao { public void selectWithLocalResources() throws Exception{ Statement stmt = null; ResultSet rs = null; try{ Connection lcon_dbConnection = getConnection(); stmt = lcon_dbConnection.createStatement(); rs = global_stmt.executeQuery("SELECT * FROM DUAL" ); } catch (Exception ex){ ex.printStackTrace(); }finally{ if (stmt != null){ stmt.close(); } if (rs != null){ rs.close(); } } } } |