-3

是否可以从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

不是所有的价值观

4

1 回答 1

0

您有 2 个选择:

  1. 修改查询:
    select logintime from auditlog where logintime > '2013-02-18 17:11:19'

  2. 从应用层过滤:

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"));  
}
于 2013-04-30T09:19:12.917 回答