- package com.blog.dao.impl;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.util.ArrayList;
- import java.util.List;
- import com.blog.dao.LinkageDao;
- import com.blog.dto.LocationBean;
- import com.blog.util.DBConnection;
- import com.mysql.jdbc.Connection;
- public class LinkageDaoImpl implements LinkageDao {
- /**
- *
- */
- private static final long serialVersionUID = -3538913064930240768L;
- public List<LocationBean> findAllLocation() {
- List<LocationBean> locationList = new ArrayList<LocationBean>();
- String sql = "select * from location";
- Connection connection = null;//数据库连接对象
- PreparedStatement pStatement = null;//Sql查询预编译对象
- ResultSet resultSet = null;//结果集对象
- try{
- connection = DBConnection.getConnection();
- pStatement = connection.prepareStatement(sql);
- resultSet = pStatement.executeQuery();
- //遍历结果集
- while(resultSet.next()){
- String id = resultSet.getString(1);
- String name = resultSet.getString(2);
- String subId = resultSet.getString(3);
- String level = resultSet.getString(4);
- LocationBean locationBean = new LocationBean();
- locationBean.setId(Integer.parseInt(id));
- locationBean.setLocationName(name);
- locationBean.setSubId(Integer.parseInt(subId));
- locationBean.setLocationLevel(Integer.parseInt(level));
- locationList.add(locationBean);
- }
- }catch(Exception exception){
- exception.printStackTrace();
- }finally{
- try{
- resultSet.close();
- pStatement.close();
- pStatement.close();
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- return locationList;
- }
- }