0

I've tried connecting combobox in javafx with database but i'm not able to do it...Here's my code of fxml controller and fxml file

It isn't showing any kind of errors but still not working...

public class FXMLDocumentController implements Initializable {

 @FXML
    private Button button;
    final ObservableList options=FXCollections.observableArrayList();
    ComboBox combobox=new ComboBox(options);
    @Override // This method is called by the FXMLLoader when initialization is complete
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
         try{
             Class.forName("oracle.jdbc.driver.OracleDriver");
             Connection con=DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:xe","system","hetvi9398");
             ResultSet rs = con.createStatement().executeQuery("SELECT username FROM typebuddy;");
                while(rs.next())
                {
                    options.add(rs.getString("username"));
                }

             rs.close();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
        }
         //combobox.setItems(null);
        combobox.setItems(options);
    }
}

and this is my fxml tag for combobox

<ComboBox fx:id="combobox" editable="true" layoutX="1010.0" layoutY="56.0" prefWidth="150.0" promptText="Username" />
fabian
  • 80,457
  • 12
  • 86
  • 114
H.Patel
  • 1
  • 1
  • 7

0 Answers0