my problem is the following, I have two methods, in the first method I fill a combobox with data from a table in a database, that method works very well, showing me all the records that I insert in combobox # 1, by which I want to pass through the combobox # 1 the value of the selected String in this and then pass it to fill the combobox # 2, for it I have a Query in the second method, where I capture the value of the first combobox to fill the second, but I have not been successful, the value is empty, I do not know if I'm doing the reference wrong or not.
here I leave the code to guide me.
public void llenadocombobox2() {
Connection conn=null;
try {
ObservableList<String> listacombonombre= FXCollections.observableArrayList();
String consulta = "select nombre from entidad";
conn = DriverManager.getConnection("jdbc:sqlserver://DESKTOP-4JA6SFR:1433;databaseName=GLOSASNINO", "sa", "123");
PreparedStatement ps =conn.prepareStatement(consulta);
ResultSet rs = ps.executeQuery();
while ( rs.next() )
{
listacombonombre.add(rs.getString("nombre"));
}
entidad.setItems(listacombonombre);
} catch (SQLException e) {
e.printStackTrace();
}
}
public void llenadocombobox3() {
String DatoCombo2= entidad.getSelectionModel().getSelectedItem();
Connection conn=null;
try {
ObservableList<String> listacombonit= FXCollections.observableArrayList();
String consulta = "select nit from entidad where nombre='"+DatoCombo2+"'";
conn = DriverManager.getConnection("jdbc:sqlserver://DESKTOP-4JA6SFR:1433;databaseName=GLOSASNINO", "sa", "123");
PreparedStatement ps =conn.prepareStatement(consulta);
ResultSet rs = ps.executeQuery();
while ( rs.next() )
{
listacombonit.add(rs.getString("nit"));
}
nit.setItems(listacombonit);
} catch (SQLException e) {
e.printStackTrace();
}
llenadocombobox2();
}