为什么要调用cmp进行分页查询?
解决方案 »
- 真的真的很需要帮助!!!!!
- 关于spring的问题,请个指教一下?
- 做好的JSP网站能不能直接拿网上其他网站的HTML源码直接用?
- 如此错误:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- 请问在Jboss中如何设置实例化Ejb对象的大小呢?
- 在JBoss下部署ejb时,报错java.rmi.server.ExportException: Port already in use: 1098; nested exception is: 具体如下:
- 看到书上说 package.html可以看到所有的
- 下载的struts实例在jbuilder里编译时很多类怎么都找不到?
- 使用notepad++编写的java程序里面有中文字符,编译通不过怎么解决?
- 各位大牛 刚开始学Mybatis 我怎么看见有的人配置 resultMap里用实体类 有的人用java.util.HashMap 配置有啥诀窍啊
- struts中一个绝对难的问题!
- 我是新手
载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;
我在开发中也是这样解决。
再说我也想知道怎么样可以在cmp中很大数据量实现高效的查询