您的位置:首页 > 数据库

根据条件编辑SQL语句,执行回调函数查询

2017-03-28 10:01 411 查看
条件:
date_range	作业日期范围
10		一周内
20		两周内
30		一个月内
40		一个月之后

代码:
private SimpleDateFormat sqlsdf = new SimpleDateFormat("yyyy-MM-dd");

public String queryDateCond(int i) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_YEAR, i);
return sqlsdf.format(cal.getTime());
}

PS:
DAY_OF_MONTH	当月的第几天,从1开始
DAY_OF_WEEK	返回周几 ,返回只是Calendar定义的 SUNDAY,
MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, and SATURDAY.
DAY_OF_YEAR	当年的第几天,从1开始
具体看jdk中Calendar的类文档

String where = " o.status = 10 o.expire_date";
Date now = new Date();

if (dateRange == 10)
where = where + " <= '" + queryDateCond(7) + "' AND o.expire_date > '" + queryDateCond(-1) + "'";
if (dateRange == 20)
where = where + " <= '" + queryDateCond(14) + "' AND o.expire_date > '" + queryDateCond(-1) + "'";
if (dateRange == 30)
where = where + " <= '" + queryDateCond(31) + "' AND o.expire_date > '" + queryDateCond(-1) + "'";
if (dateRange == 40)
where = where + " > '" + queryDateCond(31) + "'";
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: