title: JavaFX: Populating a ComboBox with data from a MySQL Database, StringConverter breaking the combobox
body: <p>I have a ComboBox, which I'd like to populate with data from a database. Using the following code, the data that is displayed in the ComboBox is the ID of the value, not the <code>string</code> value.</p>
  
  <p>(Partial) Java Controller Code:</p>
  
  <pre><code>@FXML
      ComboBox studentPicker;
  @Override
      public void initialize(URL url, ResourceBundle rb) {
          String dbUsername = "root";
          String dbPassword = "x";
          String dbURL = "jdbc:mysql://localhost:3306/uia";
          try {
              Connection conn = DriverManager.getConnection(dbURL, dbUsername, dbPassword);
              data = FXCollections.observableArrayList();
              // Execute query and store result in a resultset
              ResultSet rs = conn.createStatement().executeQuery("SELECT username FROM user WHERE userrole='STUDENT';");
              while (rs.next()) {
                  //get string from db,whichever way 
                  data.add(new User(rs.getString("username")));
              }
  
          } catch (SQLException ex) {
              System.err.println("Error"+ex);
          }
  
          studentPicker.setItems(null);
          studentPicker.setItems(data);
      }
  </code></pre>
  
  <p>The <code>StringConverter</code> I tried was picked up from <a href="https://stackoverflow.com/questions/32606353/how-to-import-database-data-into-combo-box-in-javafx">How to import database data into combo box in javafx</a>, but this caused an error with the ComboBox. See image below: Image on the left is how it is supposed to be, right image is how it is when the StringConverter is added to the code.</p>
  
  <p><img src="https://i.imgur.com/gAdjhqX.png" alt="How it is supposed to be">
  <img src="https://i.imgur.com/AU7dnto.png" alt="How it is when adding the StringConverter below to the code"></p>
  
  <pre><code>studentPicker.setConverter(new StringConverter&lt;User&gt;() {
  
          @Override
          public String toString(User object) {
              return object.getName();
          }
  
          @Override
          public User fromString(String string) {
              // TODO Auto-generated method stub
              return null;
          }
      });
  </code></pre>
  
  <p>What I'd like to display is the usernames collected from the Database, but ID's like "is20x.User@4b6ca8f7" is displayed instead.
  Any suggestion to how I can solve this problem is greatly appreciated.</p>