⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 citydao.java

📁 jQuery 由 John Resig 创建于 2006 年初
💻 JAVA
字号:
package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import entity.City;

public class CityDAO {
	public List<City> getParent(){
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<City> cityList = new ArrayList<City>();
		
		String sql = "select * from citys where parent is null";
		
		conn = DBManager.getConn();
		try {
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			while(rs.next()){
				City city = new City();
				city.setId(rs.getInt("id"));
				city.setName(rs.getString("name"));
				cityList.add(city);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return cityList;
	}
	
	public List<City> getChild(int parent){
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<City> cityList = new ArrayList<City>();
		
		String sql = "select * from citys where parent = ?";
		
		conn = DBManager.getConn();
		try {
			ps = conn.prepareStatement(sql);
			ps.setInt(1, parent);
			rs = ps.executeQuery();
			while(rs.next()){
				City city = new City();
				city.setId(rs.getInt("id"));
				city.setName(rs.getString("name"));
				cityList.add(city);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return cityList;
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -