www.pudn.com > zhaobiao.rar > NewPPM.java


/** 
 *  
 */ 
package com.centralsoft.zhaobiao.admin; 
 
import java.sql.*; 
 
import com.centralsoft.zhaobiao.admin.*; 
import com.centralsoft.zhaobiao.util.*; 
 
/** 
 * @author zw 
 * 
 */ 
public class NewPPM { 
	public NewPPM() { 
	} 
	/** 
	 * 根据产品id删除该ppm记录 
	 * @param product_id 
	 */ 
	public void delPPMProductid(long product_id) { 
		Connection conn = null; 
		dataBase db = new dataBase(); 
		conn = db.getConnection(); 
		PreparedStatement ps = null; 
		ResultSet rs = null; 
		String sql = "select * from PPM where product_id = ?"; 
		try { 
			ps = conn.prepareStatement(sql); 
			ps.setLong(1,product_id); 
			rs = ps.executeQuery(); 
			while (rs.next()) { 
				delPPMid(rs.getLong("id")); 
			} 
		} catch (Exception e) { 
			System.out.println(e.getMessage()); 
		} finally { 
			try { 
				if (rs != null) { 
					rs.close(); 
				} 
				if (ps != null) { 
					ps.close(); 
				} 
				db.closeConn(); 
			} catch (Exception e) { 
				System.out.println(e.getMessage()); 
			} 
		} 
	} 
	/** 
	 * 根据ppmid删除该PPM记录,在删除该ppm记录时,会删除与之对应的price记录 
	 * @param id 
	 */ 
	public void delPPMid(long id) { 
		Connection conn = null; 
		dataBase db = new dataBase(); 
		conn = db.getConnection(); 
		PreparedStatement ps1 = null; 
		PreparedStatement ps2 = null; 
		ResultSet rs1 = null; 
		ResultSet rs2 = null; 
		String sql1 = "select * from PPM where id = ?"; 
		String sql2 = "delect from PPM where id = ?"; 
		try { 
			ps1 = conn.prepareStatement(sql1); 
			ps1.setLong(1,id); 
			rs1 = ps1.executeQuery(); 
			if (rs1.next()) { 
				NewPrice newprice = new NewPrice(); 
				newprice.delPrice(rs1.getLong("price_id")); 
			} 
		} catch (Exception e) { 
			System.out.println(e.getMessage()); 
		} finally { 
			try { 
				if (rs1 != null) { 
					rs1.close(); 
				} 
				if (ps1 != null) { 
					ps1.close(); 
				} 
			} catch (Exception e) { 
				System.out.println(e.getMessage()); 
			} 
		} 
		try { 
			ps2 = conn.prepareStatement(sql2); 
			ps2.setLong(1,id); 
			ps2.executeUpdate(); 
		} catch (Exception e) { 
			System.out.println(e.getMessage()); 
		} finally { 
			try { 
				if (ps2 != null) { 
					ps2.close(); 
				} 
			} catch (Exception e) { 
				System.out.println(e.getMessage()); 
			} 
		} 
		db.closeConn(); 
	} 
}