fooddao.java

来自「jsp/serlvet/javaBean:订餐系统」· Java 代码 · 共 53 行

JAVA
53
字号
package dao;

import bean.*;
import java.util.*;
import java.sql.*;

/**
 * 数据库的操作
 * @author dell
 *
 */
public class FoodDao {	
	BaseDao base=new BaseDao();	
	Connection conn=null;
	PreparedStatement psmt=null;
	
	//分页查询餐品信息
	public  List getFoods(int page){
		
		List foods=new ArrayList();
		ResultSet rest=null;
		String sql=null;
		int beginRow=0;
		
		if(page>1){
			beginRow=9*(page-1);
		}
		try{
			conn=base.getConn();
			sql="select top 9 * from foodInfo where foodID not in (select top "+
			beginRow+" foodID from foodInfo order by foodID) order by foodID";
			psmt=conn.prepareStatement(sql);
			rest=psmt.executeQuery();
			while(rest.next()){
				FoodBean fbean=new FoodBean();
				fbean.setFoodID(rest.getInt("foodID"));
				fbean.setFoodImage(rest.getString("foodImage"));
				fbean.setFoodName(rest.getString("foodName"));
				fbean.setFoodPrice(rest.getFloat("foodPrice"));
				fbean.setDescription(rest.getString("description"));
				fbean.setRemark(rest.getString("remark"));
				foods.add(fbean);
			}
		}catch(SQLException sexS){
			sexS.printStackTrace();
			System.out.println(sexS.getMessage());
		}finally{
			base.closeConn(conn,psmt,rest);
		}
		return foods;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?