Item State change of JComboBox and Get values from database and show Data on JTable.
try
{
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/supplimentry","root","root");
String sql="select * from inventory where Brand_Name='"+jComboBox3.getSelectedItem().toString()+"'";
java.sql.PreparedStatement pst=con.prepareStatement(sql);
DefaultTableModel tm33 = (DefaultTableModel)list1.getModel();
tm33.setRowCount(0);
TableColumn col = new TableColumn(tm33.getColumnCount());
JTableHeader header = list1.getTableHeader();
header.setBackground(Color.yellow);
ResultSet rs = pst.executeQuery(sql);
int i=0;
while(rs.next())
{
Vector v2 = new Vector();
v2.addElement(rs.getString(1));
v2.addElement(rs.getString(2));
v2.addElement(rs.getInt(3));
v2.addElement(rs.getDouble(4));
v2.addElement(rs.getDouble(5));
v2.addElement(rs.getDouble(6));
v2.addElement(rs.getString(7));
v2.addElement(rs.getString(8));
v2.addElement(rs.getDate(9));
v2.addElement(rs.getString(10));
v2.addElement(rs.getString(11));
tm33.addRow(v2);
}
con.close();
pst.close();
}
catch(Exception e)
{
System.out.println(e);
}