此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
楼主【weiwei214】截止到2008-07-18 16:06:59的历史汇总数据(不包括此帖):
发帖的总数量:1                        发帖的总分数:0                        每贴平均分数:0                        
回帖的总数量:0                        得分贴总数量:0                        回帖的得分率:0%                       
结贴的总数量:0                        结贴的总分数:0                        
无满意结贴数:0                        无满意结贴分:0                        
未结的帖子数:1                        未结的总分数:0                        
结贴的百分比:0.00  %               结分的百分比:---------------------
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html

解决方案 »

  1.   

    Iterator it = sess.createQuery(queryString)
                .list()
                .iterator();while ( it.hasNext() ) {
        Object[] obj = (Object[]) it.next();
        String schYear = obj[0];
        int  count  = obj[1];
        ....
    }
      

  2.   


    此时的list里每条数据是两个对象,一个是schYear ,一个就是country(*) 的值
    你可以这样取
    for(int i=0;i<list.size();i++){
    Object[] obj = (Object[])list.get(i);
    Date schYear = (Timestamp)obj[0];//如果schYear 是时间格式化
    int count = (int)obj[1];}
    也可以用楼上的方法。
      

  3.   


    Object[] obj = (Object[])list.get(i);  //   这个明白了就好了,list.get(i) 返回的是object[]
      

  4.   


      这一条通不过阿~~int  count  = obj[1]; 说object不能匹配int型,我强制转换成int型也不可以~~~~
      

  5.   


    这条的强制转换通不过阿`~~int count = (int)obj[1]; 。
    但是如果我要是改成Object  count[]=new Object[9999]; count[n] = obj[1] 就可以把count(*)的值取到count里,但是执行到最后的return excute();就会报错。咋办?谢拉~~~那位大侠帮我再看下`~~如何能把object中的值取到数组里呢````因为我想再前台的strut2标签里用这个数组。
      

  6.   

    我把代码贴上来~~~
    package metro.struts;import java.util.*;import org.apache.log4j.Logger;
    import org.hibernate.Query;import metro.hibernate.vo.*;
    import metro.hibernate.dao.*;import com.opensymphony.xwork2.ActionSupport;public class Sch_recinfo extends ActionSupport {

        private static final long serialVersionUID = 7047317819789938952L;
        private static final Logger log = Logger.getLogger(Sch_recinfo.class);
        
        protected ScheduleDAO scheduleDao;
        public Collection<Schedule> groupbyyearItems;
        public String msg = "";
        public Object  count[]=new Object[9999];
        public  Object getcount()
        {
         return this.count;
        }
        
        public void setcount(Object count[])
        {
         this.count=count;
        }
        
        public  String getmsg()
        {
         return this.msg;
        }
        
        public void setmsg(String msg)
        {
         this.msg=msg;
        }
        
        public String execute() throws Exception {        return super.execute();
        }
        
        
        public String listAll() throws Exception {
         int n = 0;
            Object  count1[]=new Object[9999]; 
         String mytemp;
         scheduleDao=new ScheduleDAO();
         Query queryObject = scheduleDao.groupByyear();
         List temp = queryObject.list();
            this.groupbyyearItems =temp;
            if(groupbyyearItems.size()==0){
             mytemp = "empty";
             setmsg(mytemp);
            }
            
            Iterator it = temp.iterator();
            while ( it.hasNext() ) {      
             Object[] obj = (Object[]) it.next();
             count1[n]  = (Int)obj[1]; 
       
      /************出错的就在上面这句,我想把obj[1];中的数值写道count1[n]数组里,一强制转换系统就出错,但是如果我要是改成Object  count[]=new Object[9999]; count[n] = obj[1] 就可以把count(*)的值取到count[]里,但是执行到最后的return excute();就会报错。我才学还请大侠指点************************/         n++;
            }
            setcount(count1);        System.out.println("tests");
            System.out.println(this.groupbyyearItems.size());
            if (log.isDebugEnabled()) {
                log.debug("AbstractCRUDAction - [list]: " + (groupbyyearItems !=null?""+"":"no") + " items found");
            }
           return execute();      
        }    public Collection getgroupbyyearItems() {
             return groupbyyearItems;
        }
    }