___ ___ erkimt Pass combobox value in SQL query to fill second combobox ______ qstntxt ___

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.

%pre%     
______ azszpr216905 ___

For the ComboBox it is not necessary

%pre%

This is a simple way to add values dynamically

%pre%

Modify it and use it according to your requirements.

    
___

0

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();
    }
    
asked by Sistem07 16.11.2018 в 20:49
source

1 answer

0

For the ComboBox it is not necessary

ObservableList<String> listacombonombre= FXCollections.observableArrayList();

This is a simple way to add values dynamically

patrones.getItems().addAll("XML Clientes -> MMAA_RfcReceptor_Folio+Serie_sociedad(RfcEmisor)_Importe",
                               "XML Proveedores -> MMAA_RfcEmisor_Folio+Serie+_sociedad(RfcReceptor)_Importe",
                               "XML Complementos -> COPAPRO_MMAA_RfcEmisor_sociedad(RfcReceptor)_Importe",
                               "XML SAT -> revisar"
                               );

Modify it and use it according to your requirements.

    
answered by 26.11.2018 в 01:11