⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 foodpagelog.java

📁 一个jsp的课程设计:电子商务网站
💻 JAVA
字号:
/*
 * foodPageLog.java
 *
 * Created on 2007年11月23日, 下午11:50
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package shopManage;
import java.sql.*;
import java.util.ArrayList;
import java.util.Iterator;
import shopManage.PageDataBean;
import dbpack.dbConnect;
/**
 *
 * @author liehuo
 */
public class FoodPageLog {
    /** Creates a new instance of foodPageLog */
    public FoodPageLog () {
        
    }
    //返回food表中记录数
	private int getAvailableCount()throws Exception{
		dbConnect conn = new dbConnect();
		int ret = 0;
		try{
			String strSql = "select count(*) from food";
			conn.rs = conn.sat.executeQuery(strSql);
			conn.rs.next();
			ret = conn.rs.getInt(1);
		}catch(Exception e){
		}finally {
			try{			
				conn.doClose ();
			}catch (Exception ex) {
				System.out.println("关闭数据库连接出现错误");
			}
		return ret;
		}
	}
	//根据总行数计算总页数
	private int countTotalPage(int totalRows ,int rowsPerPage) {
		if(totalRows % rowsPerPage == 0) {
			return totalRows/rowsPerPage ;
		}else{
			return totalRows/rowsPerPage + 1;
		}
	}
//返回存储了指定页数据的PageDataBean对象
	public PageDataBean getPageData(String page) throws Exception{
		int rowsPerPage = 15;
		int totalRows = getAvailableCount(); //获得表中总行数
		int totalPages = countTotalPage(totalRows,rowsPerPage); //获得总页数 
		ArrayList data = new ArrayList();
		
		PageDataBean pageBean = new PageDataBean();
		
		try{
			int pageNum = Integer.parseInt(page);
                        int topNum = (pageNum-1) * rowsPerPage;
                        String strSql = null;
			dbConnect con = new dbConnect();
                        if(topNum>0){
                          strSql = "select top "+rowsPerPage+" foodid,foodname,foodprice,foodboss from food where foodid not in (select top "+topNum+" foodid from food order by foodid desc) order by foodid desc ";  
                        }else{
                           strSql = "select top "+rowsPerPage+" foodid,foodname,foodprice,foodboss from food order by foodid desc ";
			}
			con.rs = con.sat.executeQuery (strSql);
			while(con.rs.next()) {
				ListFoodInfoBean showlist = new ListFoodInfoBean();
                                showlist.setFoodId (con.rs.getInt ("foodid"));
                                showlist.setFoodName (con.rs.getString ("foodname"));
                                showlist.setFoodPrice (con.rs.getString ("foodprice"));
                                showlist.setFoodBoss (con.rs.getString ("foodboss"));
				data.add(showlist);
				showlist = null;
			}
			con.doClose();
			pageBean.setCurPage(pageNum);
			pageBean.setData(data);
			pageBean.setTotalPage(totalPages);
			pageBean.setRowsPerPage (rowsPerPage);
			return pageBean;
		}catch(Exception e){
			System.out.println(e);
			throw e;
		}
	}
//        public static void main(String args[]){
//            FoodPageLog fp = new FoodPageLog();
//            int total = 0;
//            ArrayList al = new ArrayList();
//            PageDataBean pd  = new PageDataBean();
//            listFoodInfoBean lf = new listFoodInfoBean();
//            try{
//                total = fp.getAvailableCount ();
//                pd = fp.getPageData ("2");
//            }catch(Exception e){
//                e.printStackTrace ();
//            }
//            System.out.println (total);
//            al = pd.getData();
//            Iterator iter = al.iterator();
//            while(iter.hasNext()){
//                listFoodInfoBean showInfo = (listFoodInfoBean)iter.next();
//                System.out.println (showInfo.getFoodName ());
//            }
//        }
}

⌨️ 快捷键说明

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