Hi, I'm trying to select the data in the genre table with the query select sexo from genero
in a combobox, but the combobox does not return anything, this is the code that I have which is the following.
public void llenadocombobox() {
Connection conn=null;
ObservableList <String> listacombo= FXCollections.observableArrayList();
String consulta = "select sexo from genero";
try {
conn = DriverManager.getConnection("jdbc:sqlserver://DESKTOP-4JA6SFR:1433;databaseName=prueba", "sa", "123");
Statement ps =conn.createStatement();
ResultSet rs =ps.executeQuery(consulta);
while(rs.next()) {
listacombo.add(rs.getString("sexo"));
}
} catch (SQLException e) {
e.printStackTrace();
}
combo.getItems().addAll(listacombo);
}
I declare a observablelist
to save the data and then display them in the combobox. some help would be great. thanks.