| Severity | 1 |
|---|---|
| Enabled | no |
| Waivable | |
| Violation |
public void selectMultiplePrepStatements(){
PreparedStatement pstmt = null;
Connection conn = null;
try{
pstmt=conn.prepareStatement("SELECT * FROM Something");
//-- do something but no close()
pstmt=conn.prepareStatement("SELECT * FROM Something");
} catch (Exception ex){
ex.printStackTrace();
} finally {
try{
if(pstmt != null){pstmt.close();}
} catch (Exception ex){
ex.printStackTrace();
}
}
}
|
| Fix |
public void selectMultiplePrepStatements(){
PreparedStatement pstmt = null;
Connection conn = null;
try{
pstmt=conn.prepareStatement("SELECT * FROM Something");
pstmt.close();
//-- do something
pstmt=conn.prepareStatement("SELECT * FROM Something");
} catch (Exception ex){
ex.printStackTrace();
} finally {
try{
if(pstmt != null){pstmt.close();}
} catch (Exception ex){
ex.printStackTrace();
}
}
}]
|