使用 BETWEEN 过滤 Table 但数据未显示
Filtering Table using BETWEEN but data are not showing up
我正在尝试使用组合框按月过滤我的 table,但每当我 select 十月时,即使我的数据库中的时间戳是十月,也没有任何显示。
这是我的代码:
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");
}
将 rs = 添加到 pst.executeQuery();解决问题
我正在尝试使用组合框按月过滤我的 table,但每当我 select 十月时,即使我的数据库中的时间戳是十月,也没有任何显示。
这是我的代码:
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");
}
将 rs = 添加到 pst.executeQuery();解决问题