package BranchesMgr.dao.impl; /** * 城区的实现类 */ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import BranchesMgr.dao.BaseDao; import BranchesMgr.dao.CityAreaDao; import BranchesMgr.entity.CityArea; public class CityAreaDaoImpl extends BaseDao implements CityAreaDao { @Override //查询所有的城区 public List<CityArea> getCityArea() { String sql="select * from CityArea"; List<CityArea>clist=new ArrayList<CityArea>(); try { ResultSet rs=excuteQurey(sql, null); while(rs.next()){ CityArea city=new CityArea(); city.setId(rs.getInt("id")); city.setName(rs.getString("name")); clist.add(city); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ closeAll(); } return clist; } @Override //根据id查询城区信息 public CityArea cityById(int id) { CityArea city=null; List<Object> prams=new ArrayList<Object>(); String sql=null; if(id==0){ sql="select * from CityArea"; }else{ sql="select * from CityArea where id=?"; } prams.add(id); try { ResultSet rs=excuteQurey(sql, prams); if(rs.next()){ city=new CityArea(); city.setId(rs.getInt("id")); city.setName(rs.getString("name")); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ closeAll(); } return city; } }