title: How to convert selection in JavaFX ComboBox to String
body: <p>I have a form which is to be submitted to a mySQL database, where one of the inputs is a ComboBox (JavaFX).</p>
  
  <p>When submitting the input from the ComboBox, the value added to the database is </p>
  
  <pre><code>"ComboBox[id=rolePicker, styleClass=combo-box-base combo-box]"
  </code></pre>
  
  <p>not a <code>String</code> value.</p>
  
  <p>How can I solve this issue, so that the data submitted to the database is a <code>String</code> of the value selected?</p>
  
  <p>(Partial) JAVA Controller Code:</p>
  
  <pre><code>public class NewUserController implements Initializable, ControlledScreen {
  
      @FXML
      TextField nameField;
      @FXML
      TextField usernameField;
      @FXML
      TextField emailField;
      @FXML
      ComboBox rolePicker;
  
      @FXML
      public void submitUser(ActionEvent event) {
          String dbUsername = "root";
          String dbPassword = "secret";
          String dbURL = "jdbc:mysql://localhost:3306/uia";
  
          try {
              Connection conn = DriverManager.getConnection(dbURL, dbUsername, dbPassword);
              Statement statement = (Statement) conn.createStatement();
              statement.execute("INSERT INTO user (name, username, password, email, userrole) VALUES ('" + nameField.getText() + "', '" + usernameField.getText() + "', '" + usernameField.getText() + "', '" + emailField.getText() + "', '" + rolePicker + "');");
  
          } catch (SQLException e) {
              System.out.println(e);
          }
      }
  </code></pre>
  
  <p>(Partial) FXML Code:</p>
  
  <pre><code>&lt;ComboBox id="rolePicker" fx:id="rolePicker" editable="true" maxHeight="25.0" maxWidth="225.0" minHeight="25.0" minWidth="225.0" prefHeight="25.0" prefWidth="225.0" promptText="Role.." visibleRowCount="4"&gt;
      &lt;items&gt;
          &lt;FXCollections fx:factory="observableArrayList"&gt;
              &lt;String fx:value="TEACHER" /&gt;
              &lt;String fx:value="STUDENT" /&gt;
          &lt;/FXCollections&gt;
      &lt;/items&gt;
  &lt;/ComboBox&gt;
  </code></pre>