title: fill javaFX treeView from database dynamically
body: <p>I have a table on database (code, composant, parent) where each node has a parent (a parent is also a component code), I need to fill a treeView dynamically from a select </p>
  
  <pre><code>@FXML
  private TreeView tree;//declaration of the treeView
  HashMap&lt;Integer, composant&gt; node = new HashMap&lt;&gt;(); //for child nodes
  HashMap&lt;Integer, composant&gt; pere = new HashMap&lt;&gt;(); //for parent nodes
  composant c; //object from component class
  
  private void fillTree(String idSys) {
      String query = "SELECT * FROM composant WHERE id=?";
      try {
          ps = cnx.prepareStatement(query);
          ps.setString(1, idSys);
          rs = ps.executeQuery();
  
          while (rs.next()) {
              int code = rs.getInt("code");
              String composant = rs.getString("composant");
              int parent = rs.getInt("parent");
              String niveau = rs.getString("niveau");
              int id = rs.getInt("id");
  
              c = new composant(code, composant, niveau, parent, id);
              node.put(code, c);
              pere.put(parent, c);
          }
          ps.close();
          rs.close();
      } catch (Exception e) {
          System.err.println("Error" + e);
      }
  
      TreeItem&lt;String&gt; system = new TreeItem&lt;&gt;(sys);
      //brows and fill parents node
      for (Integer k : pere.keySet()) {
          composant p = pere.get(k);
          TreeItem&lt;String&gt; parent = new TreeItem&lt;&gt;();
          parent.setValue(p.getComposant());
  
          //brows and fill child hashmap
          for (Integer i : node.keySet()) {
              composant c = node.get(i);
              TreeItem&lt;String&gt; noeud = new TreeItem&lt;&gt;();
              noeud.setValue(c.getComposant());
  
              if (c.getParent() == k) {
                  //if the parent = 1 it must attach to the root node
                  if (k == 1) {
                      system.getChildren().add(noeud);
                  } else {
                      parent.getChildren().add(noeud);
                  }
              }
          }
      }
      tree.setRoot(system);
  }
  </code></pre>
  
  <p>when compiling nothing appear on the window 
  this is what I've got
  <a href="https://i.stack.imgur.com/YBWYS.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YBWYS.jpg" alt="enter image description here"></a></p>