2 gxx20111214 gxx20111214 于 2015.06.19 15:38 提问

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

![图片说明](http://img.ask.csdn.net/upload/201506/19/1434699386_154547.png)

2个回答

qq_29161425
qq_29161425   2015.06.19 16:16

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

gxx20111214
gxx20111214   2015.06.19 16:16

当ls返回的数据太多,for循环 创建Query太多,没关闭的情况下,会报游标超出错误。。。

Csdn user default icon
上传中...
上传图片
插入图片