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


package dao; 
 
import java.sql.Connection; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.util.ArrayList; 
 
import bean.Bh; 
 
import common.DBConnection; 
 
public class BhDao { 
	public int addBh(Bh u){ 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con 
					.prepareStatement("insert into bh(zt,lssid,spid,lssdz,xqsx,bz) values(?,?,?,?,getdate()+convert(int,?) ,?)"); 
			ps.setString(1, u.getZt()); 
			ps.setString(2, u.getLssid()); 
			ps.setString(3, u.getSpid()); 
			ps.setString(4, u.getLssdz()); 
			ps.setString(5, u.getXqsx()); 
			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 updateBh(Bh u){ 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con 
					.prepareStatement("update bh set zt=?,lssid=?,spid=?,lssdz=?,xqsx=?,bz=? where id=?"); 
			ps.setString(1, u.getZt()); 
			ps.setString(2, u.getLssid()); 
			ps.setString(3, u.getSpid()); 
			ps.setString(4, u.getLssdz()); 
			ps.setString(5, u.getXqsx()); 
			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 deleteBh(String id){ 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con 
					.prepareStatement("delete from  bh 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<Bh> getAllBh(){ 
		ArrayList<Bh> userList = new ArrayList<Bh>(); 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con.prepareStatement("select id, bz,lssdz,lssid,spid,xqsx,zt from bh"); 
			ResultSet rs = ps.executeQuery(); 
			while (rs.next()) { 
				Bh i=new Bh(); 
				i.setId(rs.getString("id")); 
				i.setBz(rs.getString("bz")); 
				i.setLssdz(rs.getString("lssdz")); 
				i.setLssid(rs.getString("lssid")); 
				i.setSpid(rs.getString("spid")); 
				i.setXqsx(rs.getString("xqsx")); 
				i.setZt(rs.getString("zt")); 
				userList.add(i); 
			} 
			DBConnection.close(con); 
		} catch (SQLException e) { 
			e.printStackTrace(); 
			return null; 
		} 
		return userList;					 
	} 
	public Bh getBhInfoById(String id){ 
		Connection con = DBConnection.getDBConnection(); 
		try { 
			PreparedStatement ps = con.prepareStatement("select id, bz,lssdz,lssid,spid,xqsx,zt  from Bh where id=?"); 
			ps.setString(1, id); 
			ResultSet rs = ps.executeQuery(); 
		 
			if(rs.next()) { 
				Bh i=new Bh(); 
				i.setId(rs.getString("id")); 
				i.setBz(rs.getString("bz")); 
				i.setLssdz(rs.getString("lssdz")); 
				i.setLssid(rs.getString("lssid")); 
				i.setSpid(rs.getString("spid")); 
				i.setXqsx(rs.getString("xqsx")); 
				i.setZt(rs.getString("zt")); 
				DBConnection.close(con); 
				return i; 
			} 
			return null; 
		} catch (SQLException e) { 
			e.printStackTrace(); 
			return null; 
		}				 
	}		 
}