ITeye博客

String与StringBuffer传参的区别(1)

roses · 2011-03-26 11:57 · 技术类 · 编程语言 · Markdown

private void getValue(StringBuffer denIszero, StringBuffer denIsNull){

    Connection conn = null;
    
    Statement stmt = null;
    
    ResultSet rset = null;
    
    conn = getConnection();
    
    Map<String, StringBuffer> map = new HashMap<String, StringBuffer>();
    try
    {
        stmt = conn.createStatement();
        
        StringBuffer str = new StringBuffer();
        
        str.append("select t.id,t.value from t_sys_parameter t where t.id in ('");
        str.append(Constants.DEN_ZERO_DISPLAY);
        str.append("' , '");
        str.append(Constants.DEN_ZERO_IS_USE);
        str.append("' , '");
        str.append(Constants.DEN_NUM_NULL_DISPLAY);
        str.append("' , '");
        str.append(Constants.DEN_NUM_NULL_IS_USE);
        str.append("')");
        
        //从数据库中获取ID和VALUE
        rset = stmt.executeQuery(str.toString());
        
        //把从数据库中获取的结果集循环放在MAP里,ID字段为键,value字段为值
        while(rset.next())
        {
           map.put(rset.getString("id"), new StringBuffer(rset.getString("value")));
        }
        
        //当分母为零时,判断它是否被启用,如果启用了,返回结果为1,否则为0
        String zeroValue = map.get(Constants.DEN_ZERO_IS_USE).toString();
        //如果返回为0,那么特殊标记为空
        if(Constants.DEN_ZERO_IN_USE.equals(zeroValue))
        {
            denIszero = null;
        }
        
        else
        {
            //如果返回1,特殊标记为从数据库中取得的值
           denIszero.append(map.get(Constants.DEN_ZERO_DISPLAY));
        }
        
       //当分子为空或分母为空时,判断它是否被启用,如果启用了,返回结果为1,否则为0
        String nullValue = map.get(Constants.DEN_NUM_NULL_IS_USE).toString();
        //如果返回为0,那么特殊标记为空
        if(Constants.DEN_NULL_IN_USE.equals(nullValue))
        {
            denIsNull = null;
        }
        
        else
        {
            //如果返回1,特殊标记为从数据库中取得的值
            denIsNull.append(map.get(Constants.DEN_NUM_NULL_DISPLAY));
        }
            
    }
    catch (SQLException e)
    {
        log.exceptionLog("SQLBuilderDAO.getCount()", e);
    }
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。