I have created 2 comboBoxes.
The 1st comboBox drop down is created based on a radioButton selection.
The 2nd comboBox drop down list is decided based on the selection made in the 1st comboBox.
The first comboBox pulls its list from a column within one of my SQLite tables.
How can I get the the first comboBox's selection (which is the category column in the table) to cross-reference the selection ID (Cat_ID)?
Example table_1:
Cat_ID Category 1. Test1 2. Test2
In the 2nd comboBox, I want to listen for a selection to be made in the 1st comboBox. Then take the 1st comboBox selection ID (Cat_ID) to query my SQLite database for all entries with the matching ID number on a second table and list them in the 2nd comboBox.
Hopefully this makes sense.
Here is the first comboBox code:
radioButton_1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
try{
con = DriverManager.getConnection("jdbc:sqlite:WB.db");
con.setAutoCommit(false);
stmt = con.createStatement();
String s = "SELECT * FROM Categories;";
rs = stmt.executeQuery(s);
while(rs.next()){
comboBox.removeItem(rs.getString(2));
comboBox.addItem(rs.getString(3));
}
}
catch (SQLException e){
JOptionPane.showMessageDialog(null, "didnt pull from database");
}finally{
try{
stmt.close();
rs.close();
con.close();
}catch (Exception e){
JOptionPane.showMessageDialog(null, "ERROR CLOSE");
}
}
}
});