为什么要调用cmp进行分页查询?

解决方案 »

  1.   

    分页还是用sessionbean算了,太特殊了
      

  2.   

    分页是表现层的问题(JSP),CMP应专注与后台逻辑。
      

  3.   

    我来帮你:
    载cmp中写一个方法,实现他即可

    public Collection ejbFindSpecialMappingNewstarByPrimaryKey(int startRow, int endRow) throws FinderException, NSException{
            String sql ="";
            BigDecimal newstar_id = null;
            Connection conn = null;
            PreparedStatement pstmt = null;
            ResultSet rs = null;
            Vector v = new Vector();
            NewstarPK key;
            try {
                System.out.println(
                    "ejbFindSpecialMappingNewstarByPrimaryKey() called in NewstarBean");
                conn = ConnectionUtil.getConnection(); //getConnection()
                sql = " select * from (select ID, rownum row_id from newstar) "
                    + "where row_id>=? and row_id<=?";
                pstmt = conn.prepareStatement(sql);
                pstmt.setInt(1, startRow);
                pstmt.setInt(2, endRow);
                rs = pstmt.executeQuery();
                while (rs.next()) {
                    newstar_id = rs.getBigDecimal("ID");
                    key = new NewstarPK(newstar_id);
                    key.flag = 3;
                    v.addElement(key);
                }
                return v;
            }
            catch (Exception e) {
                System.out.println(
                    "Warning,the method of ejbFindSpecialMappingNewstarByPrimaryKey() is wrong in NewstarBean!");
                e.printStackTrace();
                throw NSExceptionUtil.getNSException(
                    "Warning,the method of ejbFindSpecialMappingNewstarByPrimaryKey() is wrong in NewstarBean!");
            }
            finally {
                try {
                    if (pstmt != null)
                        pstmt.close();
                    if (conn != null)
                        conn.close();
                }
                catch (Exception ep) {
                    throw NSExceptionUtil.getNSException(
                        "Warning,connecting db is wrong!(newstar)");
                }
            }
        }
    session 中调用
     System.out.println("NewstarSessionBean getAccountList(PageRoll pr) called");
                resultCount = newstarHome.getResultCounts();
                System.out.println("resultCount ========" + resultCount);
                currentPage = pr.getCurrentPage();
                System.out.println("currentPage========" + currentPage);
                pageSize = pr.getPageSize();
                System.out.println("pageSize========" + pageSize);
                pageCount = (resultCount + pageSize - 1)/ pageSize; //calcute page's count
                System.out.println("PageCount ===============" + pageCount);
                if(currentPage<1){
                    currentPage = 1;//As current page less than one,set it to main page
                }
                else if (currentPage >= pageCount) {
                    currentPage = pageCount; //As current page more than sum of page, set final page
                }
                System.out.println("currentPage ===============" + currentPage);
                pageRoll.setResultCount(resultCount);
                pageRoll.setPageCount(pageCount);
                startRow = (currentPage - 1) * pageSize + 1;
                endRow = startRow + pageSize - 1;
                if(endRow>resultCount)
                    endRow = resultCount;
                System.out.println("startRow : endRow ==========" + startRow + ":" + endRow);
                Iterator  i = newstarHome.findSpecialMappingAccoutByPrimaryKey(startRow, endRow).iterator();
                while(i.hasNext()){
                    newstar = (Newstar) javax.rmi.PortableRemoteObject.narrow(
                        i.next(), Newstar.class);
                    nSMainDTO = new NSMainDTO();
                    nSMainDTO.setID(newstar.getId().intValue());
                    nSMainDTO.setName(newstar.getName());
                    nSMainDTO.setCareer(newstar.getCareer().toString());
                    nSMainDTO.setConsultant(JspUtil.getString(newstar.getConsultant()));
                    System.out.println("date==========================" + newstar.getRegDate());
                    nSMainDTO.setReg_date(JspUtil.getString(newstar.getRegDate()));
                    listAccounts.add(nSMainDTO);
                }
                pageRoll.setList(listAccounts);
                return pageRoll;
      

  4.   

    netcobol(初学者) ,是方法是使用Oracle中的一个特有字段ROWID,来解决这个问题了。
    我在开发中也是这样解决。
      

  5.   

    你这个是bmp了,bmp分页的查询我是知道的,cmp中可以直接写sql语句吗?
      

  6.   

    bdsc,我知道可以别的方法可以做到,但是我就想用这个方式实现一下,这不是为了学习吗
     再说我也想知道怎么样可以在cmp中很大数据量实现高效的查询