从制造到创造
软件工程师成长之路
posts - 292,  comments - 96,  trackbacks - 0

在再保系统中,我们有时候会以某个日期作为查询条件,如在“参数维护”的某个模块中,需要将“生效日期”作为查询条件。

我们在JSP中使用JS插件输入“yyyy-mm-dd”格式的日期,但是数据库(DB2)中的字段是“TimeStamp”,而我们在DBean中用VO接这个字段是用“Date”类型,这样在做查询的Dao类的方法中,我们要对这个字段进行处理。

首先定义一种格式变量:
SimpleDateFormat myFmt = new SimpleDateFormat("yyyy-MM-dd");

然后将Date类型的变量进行格式化:
myFmt.format(reCededRateVO.getBoundDate())

这样会得到“yyyy-MM-dd”格式的日期,然后就可以放到Sql语句中作为条件进行查询了。

/**
 * description: 根據公司別、再保類別查詢與之相符合的紀錄
 * 
 * 
@param reCededRateVO
 *            ReCededRateVO
 * 
@param startRow
 *            起始行
 * 
@param numberOfRows
 *            讀取行數
 * 
@return List 結果集
 * 
@throws DbAccessException
 *             數據庫訪問異常
 
*/
public List selectListByCode(ReCededRateVO reCededRateVO,
        
int startRow, int numberOfRows) throws DbAccessException {
    
if (DEBUGLOG.isDebugEnabled()) {
        DEBUGLOG.debug(
"[ReCededRateDataDao.selectListByCode()]"
                
+ "[begin]");
    }
    SimpleDateFormat myFmt 
= new SimpleDateFormat("yyyy-MM-dd");
    StringBuffer hqlBuff 
= new StringBuffer(
            
"from ReCededRateData as t where 1=1");
    
    
// 公司別
    if (!"".equals(reCededRateVO.getCompanyFlag())
            
&& reCededRateVO.getCompanyFlag() != null) {
        hqlBuff.append(
" and t.id.companyFlag = '"
                
+ reCededRateVO.getCompanyFlag() + "'");
    }
    
    
// 再保類別
    if (!"".equals(reCededRateVO.getReinsuranceClass())
            
&& reCededRateVO.getReinsuranceClass() != null) {
        hqlBuff.append(
" and t.id.reinsuranceClass = '"
                
+ reCededRateVO.getReinsuranceClass() + "'");
    }
    
    
// 再保層次
    if (!"".equals(reCededRateVO.getReinsuranceLevel())
            
&& reCededRateVO.getReinsuranceLevel() != null) {
        hqlBuff.append(
" and t.id.reinsuranceLevel = '"
                
+ reCededRateVO.getReinsuranceLevel() + "'");
    }
    
    
// 生效日期
    if (!"".equals(reCededRateVO.getBoundDate())
            
&& reCededRateVO.getBoundDate() != null) {
        hqlBuff.append(
" and t.endDate >= '"
                
+ myFmt.format(reCededRateVO.getBoundDate())
                
+ "' and t.id.boundDate <= '"
                
+ myFmt.format(reCededRateVO.getBoundDate()) + "'");
    }        
    
    hqlBuff.append(
" order by t.id.companyFlag asc, t.id.boundDate asc,"
            
+ "t.id.reinsuranceClass asc, t.id.reinsuranceLevel asc,"
            
+ "t.id.reCompanyCode asc, t.id.bodyFlag asc");
    
// 以公司別+生效日期+再保類別排序+再保層次+再保公司+體位別");
    
    List list 
= this.hQueryByPage(hqlBuff.toString(), startRow,
            numberOfRows);
    
if (list != null && list.size() > 0) {
        
if (DEBUGLOG.isDebugEnabled()) {
            DEBUGLOG.debug(
"[selectListByCode()]select list success![end]");
        }
        
return list;
    } 
else {
        
if (DEBUGLOG.isDebugEnabled()) {
            DEBUGLOG.debug(
"[selectListByCode()]select list return null!"
                    
+ "[end]");
        }
        
return null;
    }
}
posted on 2007-10-09 15:41 CoderDream 阅读(703) 评论(0)  编辑  收藏 所属分类: 再保系统

只有注册用户登录后才能发表评论。


网站导航:
 

<2007年10月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

常用链接

留言簿(9)

我参与的团队

随笔分类(245)

随笔档案(239)

文章分类(3)

文章档案(3)

收藏夹(576)

友情链接

搜索

  •  

积分与排名

  • 积分 - 454200
  • 排名 - 115

最新评论

阅读排行榜

评论排行榜