日期:2014-05-17 浏览次数:20954 次
<%
    final int PAGE_SIZE = 4;
    int pageNo = 1;
    String strPageNo = request.getParameter("pageNo");
    if (strPageNo != null && !strPageNo.trim().equals("")) {
        try {
            pageNo = Integer.parseInt(strPageNo);
        } catch (NumberFormatException e) {
            pageNo = 1;
        }
    }
    if (pageNo <= 0)
        pageNo = 1;
    int totalPages = 0;
    List<Article> articles = new ArrayList<Article>();
    Connection conn = DB.getConn();
    Statement stmtCount = DB.createStmt(conn);
    ResultSet rsCount = DB.executeQuery(stmtCount,
            "select count(*) from article where pid = 0");
    rsCount.next();
    int totalRecords = rsCount.getInt(1);
    totalPages = (totalRecords + PAGE_SIZE - 1) / PAGE_SIZE;
    if (pageNo > totalPages)
        pageNo = totalPages;
    Statement stmt = DB.createStmt(conn);
    int startPos = (pageNo - 1) * PAGE_SIZE;
    String sql = "select * from article where pid = 0 order by pdate desc limit "
            + startPos + "," + PAGE_SIZE;
    //System.out.println(sql);
    ResultSet rs = DB.executeQuery(stmt, sql);
//System.out.println(rs);这里rs输出的是空值,不知道是哪里出错了
    while (rs.next()) {
        Article a = new Article();
        a.initFromRs(rs);
        articles.add(a);
    }
    DB.close(rsCount);
    DB.close(stmtCount);
    DB.close(rs);
    DB.close(stmt);
    DB.close(conn);
%>
String sql = "select * from article where pid = 0 order by pdate desc limit "
            + startPos + "," + PAGE_SIZE;
------解决方案--------------------
调试。。调试。。一调试就知道哪null指针了。。