title: prepare statement object is not closed
body: <p>Is that code affecting the Performance or cause any memory leaks? Here <code>PreparedStatement</code> object is not closed and doesn’t have the reference to close. Any suggestion on this?</p>
  
  <pre><code>private ResultSet getEmpData(String query){
      ResultSet rs = null;
      try {
          rs = connection.prepareStatement(query).executeQuery();
      } catch (SQLException e) {
          e.printStackTrace();
      }
      return rs;
  }
  
  public int getEmployeeSalary(){
  
      ResultSet rs = null;
      int salary  = 0 ;
      try {
          rs = getEmpData("SELECT SALARY FROM EMP WHERE NAME ='SAM'");
          while (rs.next()) {
              salary = rs.getInt(1);
          }
      } catch (SQLException e) {
      }finally{
          if (rs!= null) {
              try {
                  rs.close();
              } catch (SQLException e) {
                  e.printStackTrace();
              }
          }
      }
      return salary;
  }
  </code></pre>