parent
							
								
									40becf2e3c
								
							
						
					
					
						commit
						a9a7015274
					
				| @ -0,0 +1,77 @@ | |||||||
|  | package com.dao; | ||||||
|  | 
 | ||||||
|  | import java.util.*; | ||||||
|  | 
 | ||||||
|  | import java.sql.*; | ||||||
|  | 
 | ||||||
|  | import com.domain.Production; | ||||||
|  | 
 | ||||||
|  | public class ProductionDaoImpl implements ProductionDao { | ||||||
|  |      | ||||||
|  |     // 添加学生方法
 | ||||||
|  | 	    public boolean addProduction(Production s)throws SQLException{ | ||||||
|  | 	    	Connection conn = getConnection(); | ||||||
|  | 	    	String sql = "INSERT INTO Production(Pid,Price,Prom,Classify,Store) VALUES (?,?,?,?,?)";  | ||||||
|  | 	       try{ | ||||||
|  | 	  	     PreparedStatement pstmt = conn.prepareStatement(sql); | ||||||
|  | 	  	     pstmt.setInt(1, s.getPid());  | ||||||
|  | 	  	     pstmt.setString(2, s.getPrice()); | ||||||
|  | 	          pstmt.setString(3, s.getProm()); | ||||||
|  | 	          pstmt.setString(4, s.getClassify()); | ||||||
|  | 	          pstmt.setString(5, s.getStore()); | ||||||
|  | 	           | ||||||
|  | 	          pstmt.executeUpdate(); | ||||||
|  | 	          return true; | ||||||
|  | 	       }catch(SQLException sqle){ | ||||||
|  | 	   	      System.out.println(sqle); | ||||||
|  | 	   	      return false; | ||||||
|  | 	        }         | ||||||
|  |     } | ||||||
|  |     // 检索学生方法
 | ||||||
|  | public List<Production> listProduction()throws SQLException{ | ||||||
|  |     Connection conn = getConnection();   | ||||||
|  | 	String sql = "SELECT * FROM Production";  | ||||||
|  |   	  List<Production> list = new ArrayList<Production>();  | ||||||
|  |   	  try{ | ||||||
|  |   	  	PreparedStatement pstmt = conn.prepareStatement(sql); | ||||||
|  |   	     ResultSet rs = pstmt.executeQuery(); | ||||||
|  |   	     while(rs.next()){ | ||||||
|  |   	    	 int Pid = rs.getInt("Pid"); | ||||||
|  |   	       String Price = rs.getString(2); | ||||||
|  |   	       String Prom = rs.getString(3); | ||||||
|  |   	       String Classify = rs.getString(4); | ||||||
|  |   	     String Store = rs.getString(5); | ||||||
|  |   	Production s = new Production(); | ||||||
|  |   	       s.setPid(Pid); | ||||||
|  |   	       s.setPrice(Price); | ||||||
|  |   	       s.setProm(Prom); | ||||||
|  |   	      s.setClassify(Classify); | ||||||
|  |   	      s.setStore(Store); | ||||||
|  |   	       list.add(s); | ||||||
|  |   	     } | ||||||
|  |   	     return list; | ||||||
|  |   	  }catch(SQLException sqle){ | ||||||
|  |   	   	System.out.println(sqle); | ||||||
|  |   	   	return null; | ||||||
|  |   	  }         | ||||||
|  |     } | ||||||
|  |     // 删除产品
 | ||||||
|  |     public int removeProduction(int id)throws SQLException{ | ||||||
|  |         Connection conn = getConnection(); | ||||||
|  |     	String sql = "DELETE FROM Production WHERE pid=?";   | ||||||
|  |       	try{ | ||||||
|  |       	 	PreparedStatement pstmt = conn.prepareStatement(sql); | ||||||
|  |       	    pstmt.setInt(1, id); | ||||||
|  |       	    return pstmt.executeUpdate(); | ||||||
|  |       	}catch(SQLException sqle){ | ||||||
|  |       	   	System.out.println(sqle); | ||||||
|  |       	 	return 0; | ||||||
|  |       	}  | ||||||
|  |     } | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | } | ||||||
|  | 	 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
					Loading…
					
					
				
		Reference in new issue