gxx20111214 2015-06-19 07:38 采纳率: 0%
浏览 1540

hibernate处理的数据量太多,会报游标超出的错误。求大神帮忙

public List getMessageCount(String agentId,Date detectingTime,Date endTime) {
StringBuffer sbf = new StringBuffer();
sbf.append("select targetAddress,sourceaddress, count(targetAddress) from VpnRecord where 1=1");
String sf = "";
if(agentId != null && !"".equals(agentId)){
sf = " and agentid='"+ agentId+"'";
}
if(detectingTime != null && endTime != null){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String start = sdf.format(detectingTime);
String end = sdf.format(endTime);
sf += " and detectingTime >='" + start + "' and endTime <= '" + end + "'";
}
if(detectingTime == null && endTime != null){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String end = sdf.format(endTime);
sf += " and endTime <= '" + end + "'";
}
sbf.append(sf+" group by targetAddress ,sourceaddress");
List ls=this.getSession().createSQLQuery(sbf.toString()).list();
ArrayList list = new ArrayList();
int i = 0;
for(Object[] rows : ls){
i++;
String queryHql = "from VpnRecord where targetaddress='"+ rows[0]+"' and sourceaddress = '"+rows[1]+"'" + sf;
Query queryObject2 = this.getSession().createQuery(queryHql);
queryObject2.setFirstResult(0);
queryObject2.setMaxResults(10);
List list3=queryObject2.list();
VpnTemporary vpn = new VpnTemporary();
vpn.setId(i);
vpn.setTargetAddress(rows[0].toString());
vpn.setSourceAddress(rows[1].toString());
vpn.setMessageCount(Integer.parseInt(rows[2].toString()));
vpn.setList2(list3);
list.add(vpn);
log.info("target 值: " + rows[0] + "source 值: " + rows[1]+"\t 通讯总数="+Integer.parseInt(rows[2].toString()));
}
return list;
}

![图片说明](https://img-ask.csdn.net/upload/201506/19/1434699386_154547.png)
  • 写回答

2条回答 默认 最新

  • qq_29161425 2015-06-19 08:16
    关注

    vpn.setTargetAddress(rows[0].toString());
    vpn.setSourceAddress(rows[1].toString());
    vpn.setMessageCount(Integer.parseInt(rows[2].toString()));
    vpn.setList2(list3);

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据