`

SQL时间比较大小

阅读更多
public List<RBean> queryFrozenWarnHistory(Connection conn, FrozenRequestEntity req) throws Exception {
		// TODO Auto-generated method stub
		PreparedStatement pst = null;
		ResultSet rs = null; 
		RBean rBean = null;
		ArrayList<RBean> queryFrozenWarnHistoryList = new ArrayList<RBean>();
		
		String queryFrozenWarnHistorySQL = "select * from " +
				"(select rownum as rew,to_char(t1.time,'yyyy-MM-dd HH24:MI:ss') as time,t1.roadcode," +
				"t1.stake,t1.longitude,t1.latitude,t1.humidity,to_char(t1.savetime,'yyyy-MM-dd HH24:MI:ss') as savetime,t1.frozentime,t1.isfrozen,t1.dewpoint,t1.frozentem " +
				"from SNOW_WEATHER_FROZEN_HISTORY t1 where  1=1 ";
		if(null!=req.getrBean().getStartTime()&&!"".equals(req.getrBean().getStartTime())){
			queryFrozenWarnHistorySQL += " and t1.time > to_date('"+req.getrBean().getStartTime() + "','yyyy-mm-dd hh24:mi:ss') ";
		}
		if(null!=req.getrBean().getEndTime()&&!"".equals(req.getrBean().getEndTime())){
			queryFrozenWarnHistorySQL += " and t1.time < to_date('"+req.getrBean().getEndTime() + "','yyyy-mm-dd hh24:mi:ss') ";
		}
		queryFrozenWarnHistorySQL += " order by time desc)";
		
		if (!"".equals(req.getrBean().getPos()) && null != req.getrBean().getPos() ) {
			queryFrozenWarnHistorySQL += " where rew > " + req.getrBean().getPos();
		 }
		
		if(!"".equals(req.getrBean().getSize()) && null != req.getrBean().getSize()){
			if("20".equals(req.getrBean().getSize()) && !"0".equals(req.getrBean().getPos())){
				int a = Integer.parseInt(req.getrBean().getPos())+20;
				queryFrozenWarnHistorySQL += " and rew <= " + a; 
			}else{
				queryFrozenWarnHistorySQL += " and rew <= " + req.getrBean().getSize();
			}
		}
		
		pst = DBCommon.getPsm(conn, queryFrozenWarnHistorySQL);

		rs = DBCommon.getRs(pst, queryFrozenWarnHistorySQL);
		
		while(rs.next()){
			rBean = new RBean();
			rBean.setDhm(rs.getString("time"));
			rBean.setRoadcode(rs.getString("roadcode"));
			rBean.setStake(rs.getString("stake"));
			rBean.setLongitude(rs.getDouble("longitude"));
			rBean.setLatitude(rs.getDouble("latitude"));
			rBean.setHumidity(rs.getDouble("humidity"));
			rBean.setSavetime(rs.getString("savetime"));
			rBean.setFrozentime(rs.getString("frozentime"));
			rBean.setIsfrozen(rs.getString("isfrozen"));
			rBean.setDew(rs.getDouble("dewpoint"));
			rBean.setFrozentem(rs.getDouble("frozentem"));
			queryFrozenWarnHistoryList.add(rBean);
		}
		
		if(rs!=null){
			rs.close();
		}
		
		if(pst!=null){
			pst.close();
		}
		
		return queryFrozenWarnHistoryList;
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics