JComboBox and JTable in java applet
===

Here is the code for a java applet in which, the combobox will retrieve content from access database and while we select an item it must display the rows of the table which have the 'composition' field as the selected combobox item. My problem is, this works fine for the first time I select it. While the result of my first selection is being shown(which is a table), if I make a second selection on the combo box, the panel becomes blank. I want it to repeatedly show corresponding outputs for successive selections also. Kindly help me diagnose the error. Thanks in advance!

    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.util.Date;
    import java.sql.*;
    import java.text.*;
    
    public class gc implements ActionListener
    {
    JComboBox cc=new JComboBox();
    JFrame frame=new JFrame();
    JTable table;
    DefaultTableModel model;
    String query;
    int i;
    JPanel panel=new JPanel();
    
    public gc()
    {
    frame.setTitle("Composition Check");
    frame.setSize(500,500);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    JPanel p1=new JPanel();
    p1.setLayout(new FlowLayout());
    
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn=DriverManager.getConnection("jdbc:odbc:vasantham","","");
    Statement st=conn.createStatement();
    ResultSet rs=st.executeQuery("select DISTINCT composition from try");
    
    while(rs.next())
    {
     cc.addItem(rs.getString("composition"));
    }
    
    conn.close();
    }
    catch(Exception e)
    {
    }
    
    p1.add(cc);
    cc.addActionListener(this);
    frame.add(p1,BorderLayout.NORTH);
    
    frame.setVisible(true);
    }
    public void addTable(String query)
    {
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn=DriverManager.getConnection("jdbc:odbc:vasantham","","");
    Statement st=conn.createStatement();
    System.out.println(query);
    ResultSet rs=st.executeQuery(query);
    ResultSetMetaData md=rs.getMetaData();
    int cols=md.getColumnCount();
    model=new DefaultTableModel();
    
    model.addColumn("Purpose");
    model.addColumn("Name");
    model.addColumn("Manu");
    model.addColumn("Expiry");
    model.addColumn("Stock");
    model.addColumn("Cost");
    model.addColumn("Supplier");
    model.addColumn("Supplier Number");
    model.addColumn("Rack");
    
    table=new JTable(model);
    
    String[] tabledata=new String[cols];
    int i=0;
    
    while(rs.next())
    {
    for(i=0;i<cols;i++)
    {
     tabledata[i]=rs.getObject(i+1).toString();
    
    }
    model.addRow(tabledata);
    
    }
    JScrollPane scroll = new JScrollPane(table); 
    panel.setLayout(new BorderLayout());
    
    panel.add(scroll,BorderLayout.CENTER);
    frame.add(panel,BorderLayout.CENTER);
    conn.close();
    }
    catch(Exception e)
    {
    }
    }
    
    public void actionPerformed(ActionEvent evt)
    {
    String ac=(String)cc.getSelectedItem();
    System.out.println(ac);
    
    addTable("select * from try where composition='"+ac+"'");
    frame.setVisible(true);
    }
    
    public static void main(String[] args)
    {
    new gc();
    }
      
    }

