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


package dao; 
 
import java.sql.Connection; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.util.ArrayList; 
 
import bean.Lss; 
import bean.User; 
 
import common.DBConnection; 
 
public class LssDao { 
 
	public int addLss(Lss u){ 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con 
					.prepareStatement("insert into lss(lssxm,xb,sfzh,lxdh,yx,dz) values(?,?,?,?,?,?)"); 
			ps.setString(1, u.getLssxm()); 
			ps.setString(2, u.getXb()); 
			ps.setString(3, u.getSfzh()); 
			ps.setString(4, u.getLxdh()); 
			ps.setString(5, u.getYx()); 
			ps.setString(6, u.getDz()); 
			int i= ps.executeUpdate(); 
			con.commit(); 
			DBConnection.close(con); 
			return i; 
		} catch (SQLException e) { 
			e.printStackTrace(); 
		}		 
		return 0; 
	} 
	public int updateLss(Lss u){ 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con 
					.prepareStatement("update lss set lssxm=?,xb=?,sfzh=?,lxdh=?,yx=?,dz=? where id=?"); 
			ps.setString(1, u.getLssxm()); 
			ps.setString(2, u.getXb()); 
			ps.setString(3, u.getSfzh()); 
			ps.setString(4, u.getLxdh()); 
			ps.setString(5, u.getYx()); 
			ps.setString(6, u.getDz()); 
			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 deleteLss(String id){ 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con 
					.prepareStatement("delete from  lss 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<Lss> getAllLss(){ 
		ArrayList<Lss> userList = new ArrayList<Lss>(); 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con.prepareStatement("select id,dz,lssxm,lxdh,sfzh,xb,yx from lss"); 
			ResultSet rs = ps.executeQuery(); 
			while (rs.next()) { 
				Lss i=new Lss(); 
				i.setId(rs.getString("id")); 
				i.setDz(rs.getString("dz")); 
				i.setLssxm(rs.getString("lssxm")); 
				i.setLxdh(rs.getString("lxdh")); 
				i.setSfzh(rs.getString("sfzh")); 
				i.setXb(rs.getString("xb")); 
				i.setYx(rs.getString("yx")); 
				userList.add(i); 
			} 
			DBConnection.close(con); 
		} catch (SQLException e) { 
			e.printStackTrace(); 
			return null; 
		} 
		return userList;					 
	} 
	public Lss getLssInfoById(String id){ 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con.prepareStatement("select  id,dz,lssxm,lxdh,sfzh,xb,yx  from lss where id=?"); 
			ps.setString(1, id); 
			ResultSet rs = ps.executeQuery(); 
			Lss i=new Lss(); 
			if(rs.next()) { 
				i.setId(rs.getString("id")); 
				i.setDz(rs.getString("dz")); 
				i.setLssxm(rs.getString("lssxm")); 
				i.setLxdh(rs.getString("lxdh")); 
				i.setSfzh(rs.getString("sfzh")); 
				i.setXb(rs.getString("xb")); 
				i.setYx(rs.getString("yx")); 
			} 
			DBConnection.close(con); 
			return i; 
		} catch (SQLException e) { 
			e.printStackTrace(); 
			return null; 
		}				 
	}		 
}