title: How to search a database to verify it exists?
body: <p>I have been working with a java database for this class I'm just trying to search and see if the entry with the same name the user inputs exists. It used to work but for some, it keeps saying it doesn't exist in the database even if it does. If someone could give me a solution it would be greatly appreciated.</p>
  
  <pre><code>  private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {                                          
      name = txtSearch.getText();
      sr.setSearch(name);
  
      try {
          String url = "jdbc:derby://localhost:1527/Cookbook";
          Connection conn = DriverManager.getConnection(url);
          String sql = "SELECT * from RECIPES where NAME = ?";
          PreparedStatement pst = conn.prepareStatement(sql);
          pst.setString(1, name);
          ResultSet rs = pst.executeQuery();
          boolean found = false;
  
          while (rs.next()) {
              if (rs.getString(1).equalsIgnoreCase(name)) {
                  JOptionPane.showMessageDialog(null, "Found " + name);
                  found = true;                 
                  break;
  
              }
  
          }
  
          if (found) {
              this.dispose();
              modifyingRecipe m = new modifyingRecipe();
              m.setVisible(true);
  
          } else {
              JOptionPane.showMessageDialog(null, "Item Not Found!");
          }
  
      } catch (SQLException ex) {
          Logger.getLogger(CookbookApp.class.getName()).log(Level.SEVERE, null, ex);
      }
  
  }  
  </code></pre>