【发布时间】:2018-02-20 10:10:32
【问题描述】:
我正在使用 Java 7 并获取一周的记录。对于 valid_from 列,我从下面的当前日期中减去 -7。 DB中日期的格式为12-FEB-18。对于 valid_to 列,我使用的是 sysdate。我没有得到正确的 valid_from 日期。任何人都可以查看这里有什么问题。
Format formatter = new SimpleDateFormat("dd-MMM-yy");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -7);
Date todate1 = cal.getTime();
Date startdate = ((DateFormat)formatter).parse(formatter.format(todate1));
System.out.println(todayWithZeroTime);
String sql_qry = "SELECT a.ACCOUNT_ID from tableName a where a.STATUS_TYPE_KEY='ACTIVE' "
+ "and a.VALID_FROM >"
+ startdate+ " and a.VALID_TO > sysdate";
我怎样才能在这里只解析日期。目前我收到Tue Feb 13 00:00:00 GMT 2018。我想要13-FEB-18,我可以在 where 条件下将其作为变量发送。
请推荐
【问题讨论】:
-
我认为您希望在查询中使用
?占位符,然后使用 (Java 7)yourPreparedStatement.setDate或 (Java 8)yourPreparedStatement.setObject设置实际开始日期