I have a JComboBox that contains months ( september , july ... ) And one jTable And a table (Bills) in database that contains ( Id bill , date , products ..)
I want that when a choose a value from jComboBox like september it give me all products in september .
And the date format is like 2014/May/27 14:31:04
and I tried this code but it didnt work because in java i cant use :
String sql1 = "select Products from Bills where Date LIKE "?????+jComboBox1.getSelectedItem()+*" ";
(it give an error and I can't compile)
The code :
try
{
Class.forName(driver).newInstance();
Connection con = (Connection)DriverManager.getConnection(url,user,pass);
String sql1 = "select Products from Bills where Date LIKE "?????+jComboBox1.getSelectedItem()+* " ";
PreparedStatement pst = con.prepareStatement(sql1);
ResultSet rs = (ResultSet) pst.executeQuery(sql1);
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
}
catch( Exception e){
JOptionPane.showMessageDialog(null, e);
}