spring 注入的dao
Trans.exec(new Molecule<Object>(){
public void run() {
try {
for(int i=1;i<=lastRowNum;i++){ //循环每一行开始导入
Unit unit = new Unit();
XSSFRow row = sheet0.getRow(i);
XSSFCell c_address = row.getCell(0);
String address = ExcelUtil.getValue(c_address);
if(StringUtils.isBlank(address))
continue;
//address = 延安西路1328弄 7 - 16B
Pattern p=Pattern.compile("\\d*-.*");
Matcher m=p.matcher(address);
m.find();
String pStr = m.group();
String projectAddress = address.substring(0, address.indexOf(pStr));
unit.setProjectId(projectId);
if(null == projectAddressMap.getInt(projectAddress)){
ProjectAddress pa = new ProjectAddress();
pa.setProjectId(projectId);
pa.setName(projectAddress);
pa = dao.insert(pa);
projectAddressMap.put(projectAddress, pa.getId());
}
unit.setUnitAddressId(projectAddressMap.getInt(projectAddress));
String[] temp = pStr.split("-");
//插入building后获取buildingId 放到unit中
Building building = new Building();
building.setBuildingName(temp[0]);
building.setAddressId(projectAddressMap.getInt(projectAddress));
Building fetch = dao.fetch(Building.class,Cnd.where("buildingName", "=", temp[0]).and("addressId", "=", projectAddressMap.getInt(projectAddress)));
if(fetch == null)
building = dao.insert(building);
else
building = fetch;
unit.setUnitBuildingId(building.getId());
unit.setUnitName(temp[1]);
unit.setBuildingArea(Float.parseFloat(
ExcelUtil.getValue(
row.getCell(3)
)));
unit.setRoomPropertyId(roomPropertyMap.getInt(ExcelUtil.getValue(
row.getCell(1)
)));
unit.setPropertyTypeId(propertyTypeMap.getInt(ExcelUtil.getValue(
row.getCell(2)
)));
unit.setContactName(ExcelUtil.getValue(row.getCell(5)));
unit.setContactPhone(ExcelUtil.getValue(row.getCell(6)));
unit.setResidentsPopulation(StringUtils.isNoneBlank(ExcelUtil.getValue(row.getCell(9)))?(Integer.parseInt(ExcelUtil.getValue(row.getCell(9)))):null);
dao.insert(unit);
}
} catch (Exception e) {
e.printStackTrace();
throw new DaoException("e");
}
}
});
调试看着是循环正常结束了 但是报这个错误
java.lang.Exception: DEBUG STACK TRACE for PoolBackedDataSource.close().
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.close(AbstractPoolBackedDataSource.java:417)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.DisposableBeanAdapter.invokeCustomDestroyMethod(DisposableBeanAdapter.java:353)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:276)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:972)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:979)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1000)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:976)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:895)