英文:
Filtering Table using BETWEEN but data are not showing up
问题
String monthSelection = cbbMonthSearch.getSelectedItem().toString();
if (monthSelection.equals("Month")) {
System.out.println("month");
} else if (monthSelection.equals("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.equals("November")) {
System.out.println("november");
}
英文:
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");
}
答案1
得分: 1
添加rs = pst.executeQuery();即可解决问题。
英文:
Adding rs = to pst.executeQuery(); solve the problem
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论