www.pudn.com > Java_web_shipin_gongsi-.rar > ClDao.java, change:2011-05-15,size:3888b


package dao; 
 
import java.sql.Connection; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.util.ArrayList; 
 
import bean.Cl; 
import bean.Lss; 
 
import common.DBConnection; 
 
public class ClDao { 
 
	public int addCl(Cl u){ 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con 
					.prepareStatement("insert into cl(cph,cx,zzl,jsy,zt) values(?,?,?,?,?)"); 
			ps.setString(1, u.getCph()); 
			ps.setString(2, u.getCx()); 
			ps.setString(3, u.getRl()); 
			ps.setString(4, u.getJsy()); 
			ps.setString(5, u.getZt()); 
			int i= ps.executeUpdate(); 
			con.commit(); 
			DBConnection.close(con); 
			return i; 
		} catch (SQLException e) { 
			e.printStackTrace(); 
		}		 
		return 0; 
	} 
	public int updateCl(Cl u){ 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con 
					.prepareStatement("update cl set cph=?,cx=?,zzl=?,jsy=?,zt=? where id=?"); 
			ps.setString(1, u.getCph()); 
			ps.setString(2, u.getCx()); 
			ps.setString(3, u.getRl()); 
			ps.setString(4, u.getJsy()); 
			ps.setString(5, u.getZt()); 
			ps.setString(6, u.getId()); 
 
			int i= ps.executeUpdate(); 
			con.commit(); 
			DBConnection.close(con); 
			return i; 
		} catch (SQLException e) { 
			e.printStackTrace(); 
		}		 
		return 0;				 
	} 
	public int deleteCl(String id){ 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con 
					.prepareStatement("delete from  cl where id=?"); 
			ps.setString(1, id); 
			int i= ps.executeUpdate(); 
			con.commit(); 
			DBConnection.close(con); 
			return i; 
		} catch (SQLException e) { 
			e.printStackTrace(); 
		}		 
		return 0;				 
	} 
	 
	public ArrayList<Cl> getAllCl(){ 
		ArrayList<Cl> userList = new ArrayList<Cl>(); 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con.prepareStatement("select id,cph,cx,jsy,zzl,zt from cl"); 
			ResultSet rs = ps.executeQuery(); 
			while (rs.next()) { 
				Cl i=new Cl(); 
				i.setId(rs.getString("id")); 
				i.setCph(rs.getString("cph")); 
				i.setCx(rs.getString("cx")); 
				i.setJsy(rs.getString("jsy")); 
				i.setRl(rs.getString("zzl")); 
				i.setZt(rs.getString("zt")); 
				userList.add(i); 
			} 
			DBConnection.close(con); 
		} catch (SQLException e) { 
			e.printStackTrace(); 
			return null; 
		} 
		return userList;					 
	} 
	public static void main(String[] args){ 
		ClDao dao=new ClDao(); 
		dao.getAllCl(); 
	} 
	public ArrayList<Cl> getAllClByStatus(){ 
		ArrayList<Cl> userList = new ArrayList<Cl>(); 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con.prepareStatement("select id,cph,cx,jsy,zzl,zt from cl where zt=''"); 
			ResultSet rs = ps.executeQuery(); 
			while (rs.next()) { 
				Cl i=new Cl(); 
				i.setId(rs.getString("id")); 
				i.setCph(rs.getString("cph")); 
				i.setCx(rs.getString("cx")); 
				i.setJsy(rs.getString("jsy")); 
				i.setRl(rs.getString("zzl")); 
				i.setZt(rs.getString("zt")); 
				userList.add(i); 
			} 
			DBConnection.close(con); 
		} catch (SQLException e) { 
			e.printStackTrace(); 
			return null; 
		} 
		return userList;					 
	} 
	public Cl getClInfoById(String id){ 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con.prepareStatement("select id,cph,cx,jsy,zzl,zt from cl where id=?"); 
			ps.setString(1, id); 
			ResultSet rs = ps.executeQuery(); 
			Cl i=new Cl(); 
			if(rs.next()) { 
				i.setId(rs.getString("id")); 
				i.setCph(rs.getString("cph")); 
				i.setCx(rs.getString("cx")); 
				i.setJsy(rs.getString("jsy")); 
				i.setRl(rs.getString("zzl")); 
				i.setZt(rs.getString("zt")); 
			} 
			DBConnection.close(con); 
			return i; 
		} catch (SQLException e) { 
			e.printStackTrace(); 
			return null; 
		}				 
	}		 
}