使用BETWEEN进行表过滤,但数据未显示出来。

huangapple go评论69阅读模式
英文:

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 == &quot;Month&quot;) {
	System.out.println(&quot;month&quot;);
} else if (monthSelection == &quot;October&quot;) {
	try {
		con = DriverManager.getConnection(&quot;jdbc:mysql://localhost/studentlogin&quot;, &quot;root&quot;, &quot;&quot;);
		//String sql = &quot;SELECT * FROM studentregisterlogin WHERE TimeIn BETWEEN &#39;2020-10-01 00:00:00&#39; AND &#39;2020-10-31 00:00:00&#39; AND SSN=&quot; +jftfSearch.getText();
		String sql = &quot;SELECT * FROM studentregisterlogin WHERE TimeIn&gt;=&#39;2020-10-01 01:00:00&#39; AND TimeIn&lt;=&#39;2020-10-31 23:59:59&#39;&quot;;
		pst = con.prepareStatement(sql);
		pst.executeQuery();
		jtTableTime.setModel(DbUtils.resultSetToTableModel(rs));

	} catch (Exception e) {
		JOptionPane.showMessageDialog(null, e);
	}
} else if (monthSelection == &quot;November&quot;) {
	System.out.println(&quot;november&quot;);
}

答案1

得分: 1

添加rs = pst.executeQuery();即可解决问题。

英文:

Adding rs = to pst.executeQuery(); solve the problem

huangapple
  • 本文由 发表于 2020年10月8日 21:08:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/64263235.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定