Find Product and its Sub_product list through JComboBox Item State change.
private void jComboBox2ItemStateChanged(java.awt.event.ItemEvent evt) {
String name1=jComboBox2.getSelectedItem().toString();
String id=null;
try
{
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/inventory","root","root");
String sql="select BRANDID from brand where BRANDNAME='"+name1+"'";
java.sql.PreparedStatement pst=con.prepareStatement(sql);
ResultSet rs=pst.executeQuery();
while(rs.next())
{
id=rs.getString(1);
}
get(id);
}
catch(Exception e)
{
System.out.println(e);
}
}
public void get(String id)
{
DefaultComboBoxModel model = new DefaultComboBoxModel();
try
{
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/inventory","root","root");
String sql="select SUB_BRANDNAME from subbrand where BRANDID='"+id+"'";
java.sql.PreparedStatement pst=con.prepareStatement(sql);
ResultSet rs = pst.executeQuery(sql);
while(rs.next())
{
String name=rs.getString(1);
model.addElement(name);
}
jComboBox3.setModel(model);
con.close();
pst.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
subbrand();
}