ER-209 SQL Resource Management - Create Statement Number doesn't fit to Close Statement : You have to close each created SQL Statement on method level. The inspector counts the number of create- and close statement calls, and report a violation if there are less close calls as create calls. This may be wrong diagnosis if you nest your create statements in if-then-else blocks. If you use a operation in the finally block for closing your SQL resource, please define the operation name in the inspector.xml. Hammurapi will search for this method call and check the parameter list. This rule is only applicable in a connection-pooled environment.

Severity1
Enabledno
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();
                     }
                 }
             }]
             
      


Hammurapi 3 Copyright © 2004 Hammurapi Group. All Rights Reserved.