/**
*
*/
package y2sjdao;
import java.sql.SQLException;
import java.util.ArrayList;
import y2sjentity.*;
/**
* @author Administrator
*
*/
public class FoodDAO extends BaseDAO {
/**
* 增加的方法
* 继承父类的方法
*
* @throws SQLException
* @throws ClassNotFoundException
*/
// /**
// * 查询方法
// */
// public ArrayList<Product> query(int num) {
// ArrayList<Product> lst = new ArrayList<Product>();
// try {
// String sql = String.format("select top 5 * from Product where productid not in(select top %d productid from Product ) ",
// 5 * (num - 1));
// conn = getConn();
// stm = conn.createStatement();
// rs = stm.executeQuery(sql);
// while (rs.next()) {
// Product product = new Product();
// product.setProductID(rs.getInt(1));
// product.setSerialNumber(rs.getString(2));
// product.setProductName(rs.getString(3));
// product.setBrand(rs.getString(4));
// product.setModel(rs.getString(5));
// product.setPrice(rs.getDouble(6));
// product.setPicture(rs.getString(7));
// product.setDecription(rs.getString(8));
// lst.add(product);
//
// }
// } catch (ClassNotFoundException e) {
// // TODO Auto-generated catch block
// logger.debug(e.getMessage());
// } catch (SQLException e) {
// // TODO Auto-generated catch block
// logger.debug(e.getMessage());
// } finally {
// closeAll();
// }
// return lst;
//
// }
// /**
// * 查询方法
// */
// public ArrayList<Product> queryAllProduct(int num) {
// ArrayList<Product> lst = new ArrayList<Product>();
// try {
// String sql = String.format("select top 15 * from Product where productid not in(select top %d productid from Product ) ",
// 15 * (num - 1));
// conn = getConn();
// stm = conn.createStatement();
// rs = stm.executeQuery(sql);
//
// while (rs.next()) {
// Product product = new Product();
// product.setProductID(rs.getInt(1));
// product.setSerialNumber(rs.getString(2));
// product.setProductName(rs.getString(3));
// product.setBrand(rs.getString(4));
// product.setModel(rs.getString(5));
// product.setPrice(rs.getDouble(6));
// product.setPicture(rs.getString(7));
// product.setDecription(rs.getString(8));
// lst.add(product);
//
// }
// } catch (ClassNotFoundException e) {
// // TODO Auto-generated catch block
// logger.debug(e.getMessage());
// } catch (SQLException e) {
// // TODO Auto-generated catch block
// logger.debug(e.getMessage());
// } finally {
// closeAll();
// }
// return lst;
//
// }
// public ArrayList<Product> queryAll(int num) {
// ArrayList<Product> lst = new ArrayList<Product>();
// try {
// String sql = String.format("select top 10 * from Product where productid not in(select top %d productid from Product ) ",
// 10 * (num - 1));
// conn = getConn();
// stm = conn.createStatement();
// rs = stm.executeQuery(sql);
//
// while (rs.next()) {
// Product product = new Product();
// product.setProductID(rs.getInt(1));
// product.setSerialNumber(rs.getString(2));
// product.setProductName(rs.getString(3));
// product.setBrand(rs.getString(4));
// product.setModel(rs.getString(5));
// product.setPrice(rs.getDouble(6));
// product.setPicture(rs.getString(7));
// product.setDecription(rs.getString(8));
// lst.add(product);
//
// }
// } catch (ClassNotFoundException e) {
// // TODO Auto-generated catch block
// logger.debug(e.getMessage());
// } catch (SQLException e) {
// // TODO Auto-generated catch block
// logger.debug(e.getMessage());
// } finally {
// closeAll();
// }
// return lst;
//
// }
// /**
// * 根据ID来获取商品的详细信息
// */
// public Product findProductByID(int productID){
// Product product=new Product();
// try {
// String sql=String.format("select * from product where productID=%d", productID);
// conn=getConn();
// stm=conn.createStatement();
// rs=stm.executeQuery(sql);
// while(rs.next()){
// product.setProductID(rs.getInt(1));
// product.setSerialNumber(rs.getString("serialNumber"));
// product.setProductName(rs.getString("productName"));
// product.setBrand(rs.getString("brand"));
// product.setModel(rs.getString("model"));
// product.setPrice(rs.getDouble("price"));
// product.setPicture(rs.getString("picture"));
// product.setDecription(rs.getString("description"));
// }
// } catch (ClassNotFoundException e) {
// // TODO Auto-generated catch block
// logger.debug(e.getMessage());
// } catch (SQLException e) {
// // TODO Auto-generated catch block
// logger.debug(e.getMessage());
// }finally
// {
// closeAll();
// }
// return product;
// }
//
// public int getCount()
// {
// String sql="select count(*) from product";
// int count=0;
// try {
// conn=getConn();
// stm=conn.createStatement();
// rs=stm.executeQuery(sql);
// while(rs.next())
// {
// count=rs.getInt(1);
// }
// } catch (ClassNotFoundException e) {
// logger.debug(e.getMessage());
// } catch (SQLException e) {
// logger.debug(e.getMessage());
// }finally{
// closeAll();
// }
// return count;
// }
// public ArrayList<Product> findAll() {
// ArrayList<Product> lst = new ArrayList<Product>();
// try {
// String sql ="select top 8 * from Product ";
// conn = getConn();
// stm = conn.createStatement();
// rs = stm.executeQuery(sql);
// while (rs.next()) {
// Product product = new Product();
// product.setProductID(rs.getInt(1));
// product.setSerialNumber(rs.getString(2));
// product.setProductName(rs.getString(3));
// product.setBrand(rs.getString(4));
// product.setModel(rs.getString(5));
// product.setPrice(rs.getDouble(6));
// product.setPicture(rs.getString(7));
// product.setDecription(rs.getString(8));
// lst.add(product);
//
// }
// } catch (ClassNotFoundException e) {
// // TODO Auto-generated catch block
// logger.debug(e.getMessage());
// } catch (SQLException e) {
// // TODO Auto-generated catch block
// logger.debug(e.getMessage());
// } finally {
// closeAll();
// }
// return lst;
// }
/**
* 从数据库中取出所有的菜单列表的方法
*/
public ArrayList<ShowFood> queryAll(){
ArrayList<ShowFood> lst=new ArrayList<ShowFood>();
try {
String sql="select * from showfood";
conn=getConn();
stm=conn.createStatement();
rs=stm.executeQuery(sql);
while(rs.next()){
ShowFood food=new ShowFood();
food.setId(rs.getString("id"));
food.setName(rs.getString("name"));
food.setButton1(rs.getString("button1"));
food.setButton2(rs.getString("button2"));
food.setDescription(rs.getString("description"));
food.setPicture(rs.getString("picture"));
food.setPrice(rs.getDouble("price"));
lst.add(food);
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
logger.debug(e.getMessage());
} catch (SQLException e) {
// TODO Auto-generated catch block
logger.debug(e.getMessage());
}finally{
closeAll();
}
return lst;
}
/**
* 详细信息的页面,不用取出详细信息的图片
* 根据ID取出所有的信息
*/
public ShowFood findShowFoodByID(String id){
ShowFood show=new ShowFood();
try {
String sql=String.format("select * from showfood where id=%s", id);
conn=getConn();
stm =conn.createStatement();
rs=stm.executeQuery(sql);
while(rs.next()){
show.setId(rs.getString("id"));
show.setButton1(rs.getString("button1"));
show.setButton2(rs.getString("button2"));
show.setDescription(rs.getString("description"));
show.setName(rs.getString("name"));
show.setPicture(rs.getString("picture"));
show.setPrice(rs.getDouble("price"));
}
} catch (ClassNotFoundExcepti