可以从mysql中的给定模式执行结果集
喜欢
我正在使用以下代码: -
String query = "select logintime from auditlog";
pst = (PreparedStatement) connection.prepareStatement(query);
ResultSet rs = pst.executeQuery();
while (rs.next()) {
System.out.println(rs.getString("logintime"));
}
这导致我:
2013-02-18 17:02:44.0
2013-02-18 17:03:37.0
2013-02-18 17:04:14.0
2013-02-18 17:06:54.0
2013-02-18 17:07:24.0
2013-02-18 17:10:39.0
2013-02-18 17:11:19.0
2013-02-19 14:23:23.0
2013-02-19 14:25:58.0
2013-02-19 14:25:58.0
2013-02-19 14:26:41.0
2013-02-25 14:15:46.0
2013-02-25 14:32:30.0
2013-02-25 14:38:30.0
2013-03-15 10:57:46.0
我需要来自2013-02-18 17:11:19.0
的价值
2013-02-19 14:23:23.0
2013-02-19 14:25:58.0
2013-02-19 14:25:58.0
2013-02-19 14:26:41.0
2013-02-25 14:15:46.0
2013-02-25 14:32:30.0
2013-02-25 14:38:30.0
2013-03-15 10:57:46.0
并非所有值
答案 0 :(得分:0)
您有两个选择:
修改查询:
select logintime from auditlog where logintime > '2013-02-18 17:11:19'
从应用层过滤:
String query = "select logintime from auditlog"; pst = (PreparedStatement) connection.prepareStatement(query); ResultSet rs = pst.executeQuery(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); java.util.Date fistDate = sdf.parse("2013-02-18 17:11:19"); while (rs.next()) { String logtime = rs.getString("logintime"); java.util.Date parsedDate = sdf.parse(logtime); if(parsedDate.before(fistDate)){ continue; } System.out.println(rs.getString("logintime")); }