Greating from Belgium.
I am now 3 days trying to populate between values with combobox. I use Sqlite and using 4 tables to save the data in table "Recipes"
So if i choose lets say "meat" from cmbCategory, from table "sbCategory", the other combobox "cmbDescription" from table "Products" should only show what is relevant with the category "meat"
The code shown is working I can get values to the boxes. and this i pasted at the bottom "fillCombo();"
I am really desperate. 3 days searching to let this work, until i found this site. I hope you guys can help me out here. I admire the knowledge you guys have. I am a chef who is trying to write his own application. Thank you in advance. I can not pay you guys, but if you re in Belgium i can offer some coffee..
// public void fillCombo(){
try {
String sql= "Select * from sbCategorie";
String sql1= "Select * from Products";
String sql2= "Select * from UnitsRecipe";
String sql3= "Select * from Classification";
PreparedStatement pst=connection.prepareStatement(sql);
PreparedStatement pst1=connection.prepareStatement(sql1);
PreparedStatement pst2=connection.prepareStatement(sql2);
PreparedStatement pst3=connection.prepareStatement(sql3);
ResultSet rs=pst.executeQuery();
ResultSet rs1=pst1.executeQuery();
ResultSet rs2=pst2.executeQuery();
ResultSet rs3=pst3.executeQuery();
while(rs.next()){
BoxCategory.addItem(rs.getString("Categorie"));
//BoxDescription.addItem(rs.getString("Description"));
}
while(rs1.next()){
BoxDescription.addItem(rs1.getString("Description"));
}
while(rs2.next()){
BoxUnit
.addItem(rs2.getString("Unit"));
}
while(rs3.next()){
BoxClassification
.addItem(rs3.getString("Classification"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this is as shown
BoxCategory.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent arg0) {
//
//
String s=BoxCategory.getSelectedItem().toString();
String sql="Select * from Products where Category='"+s+"'";
//
try {
PreparedStatement pst=connection.prepareStatement(sql);
ResultSet rs=pst.executeQuery();
while (rs.next()){
//BoxDescription.removeAllItems();
BoxCategory.setSelectedItem(rs.getString("Description"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}