I have two combo boxes.One is a category combo box and the other is a subcategory combo Box. while selecting a category in combo-box its particular subcategory items should appear in the subcategory combo box.But we should not give the category and subcategory items in the code.it should fetch from the database.Please help me to write the code in NetBeans.
I wrote code like this, but it is not working
try
{
Connection con=databaseConnection.createConnection();
Statement stmt = con.createStatement();
ResultSet rs;
rs = stmt.executeQuery("select distinct category_name from category");
while(rs.next())
{
String cat = rs.getString("category_name");
combo_catgry.addItem(cat);
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e);
}
try
{
Connection con=databaseConnection.createConnection();
Statement stmt = con.createStatement();
ResultSet rs;
rs = stmt.executeQuery("select subCategory from category where category_name ='"+catgry+"' ");
// System.out.println(rs);
while(rs.next())
{
String cat = rs.getString("subCategory");
combo_sub.addItem(cat);
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e);
}