List 遍历出错,求指教

public class QuerySiteService {
	public static final QuerySiteService me = new QuerySiteService();

	public SiteGroup findTowerSiteByZoneId(Integer zoneid) {
		String sOpr = findStOfComById(zoneid);

		List<Site> sites = new ArrayList<Site>();
		List<Record> records = findStInfoById(zoneid);
		if (records != null) {
			Iterator<Record> iter=records.iterator();
			while(iter.hasNext()){
				Record record=iter.next();
				Site site = new Site();
				site.setId(record.get("Id"));
				site.setName(record.getStr("SiteName"));
				site.setLon(record.getDouble("Lon"));
				site.setLat(record.getDouble("Lat"));
				site.setOperator(sOpr);

				sites.add(site);
			}
			
		}		

		SiteGroup stGroup = new SiteGroup();
		stGroup.setSites(sites);

		return stGroup;
	}

	private String findStOfComById(Integer id) {
		String sql = "SELECT cxp_b_operator.`Name` " + "FROM cxp_b_operator,cxp_c_operatorlocation "
				+ "WHERE cxp_b_operator.Id  = cxp_c_operatorlocation.OperatorID "
				+ "AND cxp_c_operatorlocation.ZoneID = ?";
		Record record = Db.findFirst(sql, id);

		return record.getStr("Name");
	}

	private List<Record> findStInfoById(Integer id) {
		
		String sql = "SELECT cnp_b_site.Id,cnp_b_site.SiteName,cnp_b_property.Technology,cnp_b_property.Lat,cnp_b_property.Lon,cnp_b_property.Address "
				+ "FROM cnp_b_site,cnp_b_property,cxp_c_zonesite "
				+ "WHERE cnp_b_property.PropertyId = cnp_b_site.PropertyId "
				+ "AND cnp_b_site.Id  = cxp_c_zonesite.SiteID " + "AND cxp_c_zonesite.ZoneID = ?";
		List<Record> records = Db.query(sql, id);
		
		return records;
	}

	private List<Record> findSectorInfoById(Integer id) {
		
		String sql = "SELECT cnp_b_sector.MasterId,cnp_b_sector.Id,cnp_b_sector.SectorName,cnp_b_rfinfo.Bearing "
				+ "FROM cnp_b_sector,cnp_c_sectorrf,cnp_b_rfinfo,cxp_c_zonesite "
				+ "WHERE cnp_b_rfinfo.RFId = cnp_c_sectorrf.RFId " + "AND cnp_c_sectorrf.SectorId = cnp_b_sector.Id "
				+ "AND cnp_b_sector.MasterId = cxp_c_zonesite.SiteID " + "AND cxp_c_zonesite.ZoneID = ?";
		List<Record> records = Db.query(sql, id);

		return records;
	}

	private List<Record> findTowerNewStById(Integer id) {
		
		String sql = "SELECT tower_b_siteproperty_new.SiteId,tower_b_siteproperty_new.AntHeight,Province,City,Town,Scene "
				+ "FROM tower_b_siteproperty_new,cxp_c_zonesite "
				+ "WHERE tower_b_siteproperty_new.SiteId  = cxp_c_zonesite.SiteID " + "AND cxp_c_zonesite.ZoneID = ?";
		List<Record> records = Db.query(sql, id);

		return records;
	}

	private List<Record> findTowerInuseStById(Integer id) {

		
		String sql = "SELECT tower_b_siteproperty_inuse.SiteId,tower_b_siteproperty_inuse.AntHeight,Province,City,Town,Scene "
				+ "FROM tower_b_siteproperty_inuse,cxp_c_zonesite "
				+ "WHERE tower_b_siteproperty_inuse.SiteId  = cxp_c_zonesite.SiteID " + "AND cxp_c_zonesite.ZoneID = ? ";
		List<Record> records = Db.query(sql, id);

		return records;
	}

	private List<Record> findTowerReserveStById(Integer id) {
		
		String sql = "SELECT tower_b_siteproperty_reserve.SiteId,tower_b_siteproperty_reserve.AntHeight,Province,City,Town,Scene "
				+ "FROM tower_b_siteproperty_reserve,cxp_c_zonesite "
				+ "WHERE tower_b_siteproperty_reserve.SiteId  = cxp_c_zonesite.SiteID "
				+ "AND cxp_c_zonesite.ZoneID = ?";
		List<Record> records = Db.query(sql, id);

		return records;
	}
}

在遍历list<Record>出现如下错误:

Sql: SELECT cnp_b_site.Id,cnp_b_site.SiteName,cnp_b_property.Technology,cnp_b_property.Lat,cnp_b_property.Lon,cnp_b_property.Address FROM cnp_b_site,cnp_b_property,cxp_c_zonesite WHERE cnp_b_property.PropertyId = cnp_b_site.PropertyId AND cnp_b_site.Id  = cxp_c_zonesite.SiteID AND cxp_c_zonesite.ZoneID = ?

java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.jfinal.plugin.activerecord.Record

at com.cxp.service.api.app.query.site.QuerySiteService.findTowerSiteByZoneId(QuerySiteService.java:20)

at com.cxp.service.api.app.query.site.QuerySiteController.index(QuerySiteController.java:45)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at com.jfinal.aop.Invocation.invoke(Invocation.java:73)

at com.cxp.service.core.interceptor.KeyAuthorizedInterceptor.intercept(KeyAuthorizedInterceptor.java:31)

at com.jfinal.aop.Invocation.invoke(Invocation.java:67)

at com.jfinal.core.ActionHandler.handle(ActionHandler.java:74)

at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:74)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)

at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)

at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:495)

at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:767)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1347)

at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Thread.java:745)

也是就在执行Record record=iter.next();这句话时出现错误,求大神解答???

评论区

JFinal

2017-09-21 14:44

Db.query(sql, id); 改成
Db.find(sql, id);

注意:query 系列方法原样返回数据类型, find 系列方法将返回的数据封装成 Record 对象

vae

2017-09-21 15:08

@JFinal 可以了,这两种方式有什么区别吗?

JFinal

2017-09-21 16:29

@vae 区别前面已经说了,一个封装,一个不封装为 record

热门反馈

扫码入社