日期:2014-05-20  浏览次数:20751 次

大侠救命~~~还是那个hibernate 查询 多个count如何取出的问题
大侠救命~~~
我把代码贴上来先~~~看了代码别抽我~~我刚学,估计有很多错误的地方。还请大家多帮忙~~ 问题标在代码里了~~
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] = obj[1]; 
  
  /************出错的就在上面这句,我想把obj[1](装的是从数据库里搜出来的count(*))中的数值写道count1[n]里,现在的情况是,我可以把count(*)的值取到count[],但是执行到最后的return excute();就会报错。如果我要是把count[]改成int 型的数组的话,就会出现类型不匹配的情况。强制转换还不让用,很是郁闷啊。可能写得有点乱,总之我的目的就是想把列表每一条信息的第二条数据存到一个数组里面。然后在前台strut2里面输出这个数组的数据我比较菜,还请大侠们指点。************************/ 

  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; 
  } 
}

------解决方案--------------------

------解决方案--------------------
public String execute() throws Exception {

return SUCCESS;
}
------解决方案--------------------