title: MySQL javafx search like
body: <p>I'm losing my mind over this. Maybe its something very simple that I miss. But I can't seem to get it work. I received help from other users and edited my code. But really can't get it to work.</p>
  
  <p>This is my table in my database</p>
  
  <pre><code>+----------------+-----------------------+---------------------+
  |  colID         | colTitle              | colKeywords         |
  +----------------+-----------------------+---------------------+
  | 1              |  Jumanji              | comedy adventure    |
  | 2              |  Moana                | adventure animation |
  | 3              |  Shawshank Redemption | drama tearjerker    |
  | 4              |  Avengers             | action              |
  +----------------+-----------------------+---------------------+
  
          +-----------------------------+    +---------+    
  Search: | adventure and action movies |    |button GO|
          +-----------------------------+    +---------+
  </code></pre>
  
  <p>What I want to do is if I type "adventure and action movies" in the textfield, and after I hit the button go, the result in the tableview should be:</p>
  
  <pre><code>Jumanji
  Moana
  Avengers
  </code></pre>
  
  <p>My updated code:</p>
  
  <pre><code>public class UserMainPageController implements Initializable {
  
  
  
      Connection conn = null;
      PreparedStatement pst = null;
      ResultSet rs = null;
  
      @FXML
      private TableView table_title;
  
      @FXML
      private TableColumn titleCol;
  
      @FXML
      private TextField txt_search;
  
  
  
  
      @Override
      public void initialize(URL url, ResourceBundle rb) {
  
  
  
  
      }    
  
  
  
      @FXML
      private void logOut(ActionEvent event) throws IOException{
  
          Main.showUserLogin();
  
      }
  
  
  
  
      @FXML
      private void goSearch(ActionEvent event) throws IOException, SQLException{
  
  
         try{
  
          conn = SqlConnection.ConnectDB();
          String criteria = txt_search.getText();
          if (criteria.trim().length() == 0) { return; }
          String[] arryCriterion = criteria.split(" ");
          List&lt;String&gt; results = new ArrayList&lt;&gt;();
  
          for (int i = 0; i &lt; arryCriterion.length; i++) {
  
              List&lt;String&gt; text = populateField(arryCriterion[i], conn);
  
              results.addAll(text);
  
          }
  
          ObservableList&lt;String&gt; observableList = FXCollections.observableList(results);
  
          table_title.setItems(observableList);
  
  
      }finally{
          conn.close();
      }
  }   
  
      private List&lt;String&gt; populateField(String s, Connection conn) throws SQLException{
  
      List&lt;String&gt; myList = new ArrayList&lt;&gt;();
  
      String sql = "SELECT * FROM table_entry WHERE colTitle LIKE ? ";
  
  
      pst=conn.prepareStatement(sql);
  
      pst.setString(1, "%" + s + "%");
      rs = pst.executeQuery();
      while (rs.next()) {
          myList.add(rs.getString("colTitle"));
      }
      return myList;
  
      }
  
  
  }
  </code></pre>
  
  <p>If I press the search button, nothing seems to appear in the tableview</p>