www.pudn.com > restrant.zip > MealDao.java, change:2014-01-29,size:2438b


package com.alex.restrantol.dao; 
 
import java.sql.Connection; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.util.ArrayList; 
import java.util.List; 
 
import com.alex.restrantol.base.BaseDao; 
import com.alex.restrantol.entity.MealEntity; 
//import com.sun.java_cup.internal.internal_error; 
 
public class MealDao { 
	public final static int FIND_BY_COMMAND = 1; 
	public final static int FIND_ALL_MEALS = 2; 
	Connection con; 
	PreparedStatement ps; 
	ResultSet rs; 
	 
	public List<MealEntity> findMealAll(){ 
		List<MealEntity> list = execute("select * from meal",2); 
		return list; 
	} 
	 
	public  List<MealEntity> findMealPart(){ 
		List<MealEntity> list = execute("select top 10 * from meal",2); 
		return list; 
	} 
	 
	public MealEntity findMealById(int mealId){ 
		List<MealEntity> list = execute("select * from Meal where mealId=?",1,mealId); 
		return list.get(0); 
	} 
	 
	//public boolean addMeal(){} 
	//public boolean modifyMealById(){} 
	//public boolean delmodifyById(){} 
	 
	private List<MealEntity> execute(String sql, int model,Integer...vars) { 
		List<MealEntity> list=new ArrayList<MealEntity>(); 
		try { 
			con=new BaseDao().getConn(); 
			ps=con.prepareStatement(sql); 
			if(model == 1){ 
				for(int var : vars) 
				ps.setInt(1, var); 
			}else if(model == 2){ 
				; 
			} 
			rs=ps.executeQuery(); 
			while (rs.next()) { 
				MealEntity meal=new MealEntity(); 
				meal.setMealId(rs.getString("mealId")); 
				meal.setGastronomyId(rs.getString("gastronomy")); 
				meal.setDishSeriesId(rs.getString("dishSeriesId")); 
				meal.setTasteId(rs.getString("tasteId")); 
				meal.setMealName(rs.getString("mealName")); 
				meal.setMealSummarize(rs.getString("mealSummarize")); 
				meal.setMealParticularDescription(rs.getString("mealParticularDescription")); 
				meal.setMealPrice(Float.valueOf(rs.getFloat("mealPrice"))); 
				meal.setMemberPrice(Float.valueOf(rs.getFloat("memberPrice"))); 
				meal.setVipPrice(Float.valueOf(rs.getFloat("vipPrice"))); 
				meal.setIsRecommend(rs.getInt("isRecommend")); 
				meal.setOrderCount(rs.getInt("orderCount")); 
				meal.setIsMeatSeries(rs.getInt("isMeatSeries")); 
				meal.setMealImage(rs.getInt("mealImage")); 
				meal.setStatus(rs.getInt("status")); 
				 
				list.add(meal); 
			} 
		} catch (Exception e) { 
			e.printStackTrace(); 
		} finally { 
			new BaseDao().closeAll(con, ps, rs); 
		} 
		return list; 
	} 
}