title: Resource Leak on PreparedStatement and ResultSet
body: <p>Eclipse displays warning messages saying "Resource Leak, preparedstatement is not closed at following location"</p>
  
  <p>To me it looks like finally block takes care of closing preparedstatement and rs object. Any idea why eclipse is still complaining on resource leak?</p>
  
  <pre><code>String ruleGrpId = null;
          int finalRuleID = 0;
  
          String saveRule1 = "INSERT INTO ..";
          String saveRule2 = "INSERT INTO ";
  
          String saveRule3 = "select ..._name = ?";
  
          PreparedStatement preparedstatement = null;
          ResultSet rs = null;
  
          try {
              if (objSomeRule.getRule() == 0) {
  
                  preparedstatement = con.prepareStatement(saveRule1);
                  preparedstatement.setString(1, ruleId);
  
                  preparedstatement.executeUpdate();
  
                  //Eclipse complains here
                  preparedstatement = con.prepareStatement(saveRule2);
  
                  preparedstatement.setInt(1, ruleID_2);
                  preparedstatement.setString(2, ruleID_3);
  
                  rs =  preparedstatement.executeQuery();
  
                  if(rs.next()){
                      finalRuleID = rs.getInt(1);
                  }else{
                      //complains here
                      preparedstatement = con.prepareStatement(saveRule3);
                      preparedstatement.setString(1, ruleID_4);
                      //complains here
                      rs =  preparedstatement.executeQuery();
                      if(rs.next()){
                          finalRuleID = rs.getInt("rulegroup_id");
                      }
                  }
                  objSomeRule.setRuleID(finalRuleID);
  
              }
  
          } finally {
  
              if(preparedstatement != null){
                  preparedstatement.close();
              }
  
              if(rs != null){
                  rs.close();
              }
          }
  
          return finalRuleID;
      }
  </code></pre>