ItemStateChanged only show one Item on ComboBox from MySQL Database

16 Views Asked by At

I use jcombobox in the Netbeans application. In this case I want that when an item in the Combobox changes, the text on the label below it also changes according to the data in the SQL database.

When I use jcombobox1ItemStateChanged, the command works fine in the following syntax, All data in the combobox is displayed as it is in mysql

String str = comboPeminjaman.getSelectedItem().toString();
        showIdAnggota.setText(str);

But when I enter the syntax so that the text changes according to the database in mysql, the Combobox only displays one item. Even though in the previous case there were more than 1 items in the combobox.

try {
            st = cn.createStatement();
            String str = comboPeminjaman.getSelectedItem().toString();
            String query = "SELECT * FROM tbmahasiswa WHERE nama_mahasiswa = '"+str+"'";
            rs = st.executeQuery(query);
            
            while (rs.next()) {                
                
                
                showIdAnggota.setText(rs.getString("no_anggota"));
                valueStock.setText(rs.getString("stock_buku"));
                
               
            }
            
            
        
            
        } catch (Exception e) {
        }

Can anyone help?

I've tried tweaking the syntax but the results are nil, because in the end, only one item appears in the ComboBox, which should have several items in the ComboBox according to what's in the SQL

0

There are 0 best solutions below