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


package dao; 
 
import java.sql.Connection; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.util.ArrayList; 
 
import bean.Ps; 
 
import common.DBConnection; 
 
public class PsDao { 
	public int addPs(Ps u){ 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con 
					.prepareStatement("insert into ps(lsxz,lssid,clid,lcs,pssj,bz) values(?,?,?,?,?,?)"); 
			ps.setString(1, u.getLsxz()); 
			ps.setString(2, u.getLssid()); 
			ps.setString(3, u.getClid()); 
			ps.setString(4, u.getLcs()); 
			ps.setString(5, u.getPssj()); 
			ps.setString(6, u.getBz()); 
		 
			int i= ps.executeUpdate(); 
			con.commit(); 
			DBConnection.close(con); 
			return i; 
		} catch (SQLException e) { 
			e.printStackTrace(); 
		}		 
		return 0; 
	} 
	public int updatePs(Ps u){ 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con 
					.prepareStatement("update ps set lsxz=?,lssid=?,clid=?,lcs=?,pssj=?,bz=? where id=?"); 
			ps.setString(1, u.getLsxz()); 
			ps.setString(2, u.getLssid()); 
			ps.setString(3, u.getClid()); 
			ps.setString(4, u.getLcs().trim()); 
			ps.setString(5, u.getPssj()); 
			ps.setString(6, u.getBz());		 
			ps.setString(7,u.getId()); 
			int i= ps.executeUpdate(); 
			con.commit(); 
			DBConnection.close(con); 
			return i; 
		} catch (SQLException e) { 
			e.printStackTrace(); 
		}		 
		return 0;				 
	} 
	public int deletePs(String id){ 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con 
					.prepareStatement("delete from  ps 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<Ps> getAllPs(){ 
		ArrayList<Ps> userList = new ArrayList<Ps>(); 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con.prepareStatement("select id,bz,clid,lcs,lssid,lsxz,pssj from ps"); 
			ResultSet rs = ps.executeQuery(); 
			while (rs.next()) { 
				Ps i=new Ps(); 
				i.setId(rs.getString("id")); 
				i.setBz(rs.getString("bz")); 
				i.setClid(rs.getString("clid")); 
				i.setLcs(rs.getString("lcs")); 
				i.setLssid(rs.getString("lssid")); 
				i.setLsxz(rs.getString("lsxz")); 
				i.setPssj(rs.getString("pssj")); 
				userList.add(i); 
			} 
			DBConnection.close(con); 
		} catch (SQLException e) { 
			e.printStackTrace(); 
			return null; 
		} 
		return userList;					 
	} 
	public Ps getPsInfoById(String id){ 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con.prepareStatement("select id,bz,clid,lcs,lssid,lsxz,pssj from ps where id=?"); 
			ps.setString(1, id); 
			ResultSet rs = ps.executeQuery(); 
			 
			if(rs.next()) { 
				Ps i=new Ps(); 
				i.setId(rs.getString("id")); 
				i.setBz(rs.getString("bz")); 
				i.setClid(rs.getString("clid")); 
				i.setLcs(rs.getString("lcs")); 
				i.setLssid(rs.getString("lssid")); 
				i.setLsxz(rs.getString("lsxz")); 
				i.setPssj(rs.getString("pssj")); 
				DBConnection.close(con); 
				return i; 
			} 
			return null; 
		} catch (SQLException e) { 
			e.printStackTrace(); 
			return null; 
		}				 
	} 
}