I am trying to filter my table by Month using combobox but whenever I select October nothing shows up even the timestamp from my database is October.
Here is my code:
String monthSelection = cbbMonthSearch.getSelectedItem().toString(); if (monthSelection == "Month") { System.out.println("month"); } else if (monthSelection == "October") { try { con = DriverManager.getConnection("jdbc:mysql://localhost/studentlogin", "root", ""); //String sql = "SELECT * FROM studentregisterlogin WHERE TimeIn BETWEEN '2020-10-01 00:00:00' AND '2020-10-31 00:00:00' AND SSN=" +jftfSearch.getText(); String sql = "SELECT * FROM studentregisterlogin WHERE TimeIn>='2020-10-01 01:00:00' AND TimeIn<='2020-10-31 23:59:59'"; pst = con.prepareStatement(sql); pst.executeQuery(); jtTableTime.setModel(DbUtils.resultSetToTableModel(rs)); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } else if (monthSelection == "November") { System.out.println("november"); }
Advertisement
Answer
Adding rs = to pst.executeQuery(); solve the problem