📄 771284.xml
字号:
<?xml version='1.0' encoding='GB2312'?>
<?xml-stylesheet type='text/xsl' href='../csdn.xsl'?>
<Topic>
<Issue>
<PostUserNickName>恶泓</PostUserNickName>
<rank>一级(初级)</rank>
<ranknum>user1</ranknum>
<credit>100</credit>
<TopicId>771284</TopicId>
<TopicName>JSP分页的有关问题。</TopicName>
<PostUserId>116705</PostUserId>
<PostUserName>xuehong_BP</PostUserName>
<RoomName>JSP</RoomName>
<ReplyNum>10</ReplyNum>
<PostDateTime>2002-6-1 17:18:38</PostDateTime>
<Point>60</Point>
<ReadNum>0</ReadNum>
<RoomId>28</RoomId>
<EndState>2</EndState>
<Content>请问当我执行完一SQL语句后,返回ResultSet,那么,这个ResultSet有没有提供获得有多少条记录的方法,真的要自己去数吗?还有别的方法吗?</Content>
</Issue>
<Replys>
<Reply>
<PostUserNickName>晓彬</PostUserNickName>
<rank>两星(中级)</rank>
<ranknum>star2</ranknum>
<credit>135</credit>
<ReplyID>5017977</ReplyID>
<TopicID>771284</TopicID>
<PostUserId>173450</PostUserId>
<PostUserName>Andrawu</PostUserName>
<Point>0</Point>
<Content>jdbc2.0好象有,没有仔细的研究过。
http://www.csdn.net/expert/topic/725/725795.xml?temp=.9426538</Content>
<PostDateTime>2002-6-1 17:48:31</PostDateTime>
</Reply>
<Reply>
<PostUserNickName>晓彬</PostUserNickName>
<rank>两星(中级)</rank>
<ranknum>star2</ranknum>
<credit>135</credit>
<ReplyID>5017982</ReplyID>
<TopicID>771284</TopicID>
<PostUserId>173450</PostUserId>
<PostUserName>Andrawu</PostUserName>
<Point>0</Point>
<Content>jdbc2.0好象有,没有仔细的研究过。
http://www.csdn.net/expert/topic/725/725795.xml?temp=.9426538</Content>
<PostDateTime>2002-6-1 17:48:59</PostDateTime>
</Reply>
<Reply>
<PostUserNickName>紫剑伊</PostUserNickName>
<rank>四级(中级)</rank>
<ranknum>user4</ranknum>
<credit>100</credit>
<ReplyID>5018599</ReplyID>
<TopicID>771284</TopicID>
<PostUserId>116191</PostUserId>
<PostUserName>zijianyi</PostUserName>
<Point>0</Point>
<Content>Rst=Stmt.executeQuery("select count(*) from table");</Content>
<PostDateTime>2002-6-1 19:06:25</PostDateTime>
</Reply>
<Reply>
<PostUserNickName>紫剑伊</PostUserNickName>
<rank>四级(中级)</rank>
<ranknum>user4</ranknum>
<credit>100</credit>
<ReplyID>5018606</ReplyID>
<TopicID>771284</TopicID>
<PostUserId>116191</PostUserId>
<PostUserName>zijianyi</PostUserName>
<Point>0</Point>
<Content>Rst=Stmt.executeQuery("select count(*) from table");
Rst.next();
int num=Rst.getInt(1);</Content>
<PostDateTime>2002-6-1 19:07:22</PostDateTime>
</Reply>
<Reply>
<PostUserNickName>恶泓</PostUserNickName>
<rank>一级(初级)</rank>
<ranknum>user1</ranknum>
<credit>100</credit>
<ReplyID>5023463</ReplyID>
<TopicID>771284</TopicID>
<PostUserId>116705</PostUserId>
<PostUserName>xuehong_BP</PostUserName>
<Point>0</Point>
<Content>zijianyi(紫剑伊) 仁兄的例子我已经在前面的贴子看了。
我的意思是问:
Rst=Stmt.executeQuery("select * from table where a>b");后
Rst内有没有方法可以获得它的纪录条数?num=Rst.get**** 这种方法。
</Content>
<PostDateTime>2002-6-2 10:08:59</PostDateTime>
</Reply>
<Reply>
<PostUserNickName>JK1</PostUserNickName>
<rank>三级(初级)</rank>
<ranknum>user3</ranknum>
<credit>95</credit>
<ReplyID>5025071</ReplyID>
<TopicID>771284</TopicID>
<PostUserId>142852</PostUserId>
<PostUserName>JK_10000</PostUserName>
<Point>5</Point>
<Content>刚才到:
http://java.sun.com/j2se/1.4/docs/api/java/sql/ResultSet.html
里也没有找到直接满足条件的方法或属性
不过应该可以先用last(),再用getRow()得到的值就应该是总数了。
不过如果是这样的话,它的实际过程是先筛选出所有满足条件的内容,会耗用很多的资源(尤其是内存)。
如果你的数据库是SQL,JK建议你先用zijianyi(紫剑伊) 兄的方式得到总笔数,再把你要显示出的资料select出来:
例如:每页20笔,你要显示第三页,用:select top 60 * from tableName where ………</Content>
<PostDateTime>2002-6-2 12:24:03</PostDateTime>
</Reply>
<Reply>
<PostUserNickName>chiwp</PostUserNickName>
<rank>一级(初级)</rank>
<ranknum>user1</ranknum>
<credit>100</credit>
<ReplyID>5026304</ReplyID>
<TopicID>771284</TopicID>
<PostUserId>151992</PostUserId>
<PostUserName>goldsoft</PostUserName>
<Point>40</Point>
<Content>	int PageSize=15; //设置每张网页显示两条记录
	int ShowPage=1; //设置欲显示的页数
	int RowCount=0; //记录数目
	int PageCount=0; //分页后的总页数
strSQL="select * from aaa";
        Rs=Stmt.executeQuery(strSQL);
	if(Rs.last()){
		RowCount=Rs.getRow();
		PageCount=((RowCount%PageSize)==0?(PageCount/PageSize):(RowCount/PageSize)+1);
		String PageNo=request.getParameter("pageno");
		if(PageNo!=null){
			rc=Integer.parseInt(PageNo);
			if(rc>0)ShowPage=rc;
			else {
				if(rc<0)ShowPage--;
				else ShowPage++;
			}
			if(ShowPage<1)ShowPage=1;
			if(ShowPage>PageCount)ShowPage=PageCount;
		}
		Rs.absolute((ShowPage-1)*PageSize+1);
	}
	else {
		RowCount=0;
		PageCount=0;
	}
        <table height=25 cellspacing=0 cellpadding=0 width=280 border=0>
          <form name=form2 action="" method=post>
            
            <tr> 
              <td class=blue3 align=middle height=28>共<%=PageCount%>页             
                <select    
            onChange=onSelectOption(document.form2.pageno); name=papeno>
		<%for(i=1;i<=PageCount;i++){
			if(i==ShowPage)out.println("<option value="+i+" selected>"+i+"</option>");
			else out.println("<option value="+i+">"+i+"</option>");
		}
		%>
                 </select>
                 第<%=ShowPage%>页  
		<%if(ShowPage==1)out.println("上一页");
		 else out.println("<a class=blue3 href=\"manager.jsp?pageno=-1\">上一页</a>");%>
		<%if(ShowPage>=PageCount)out.println("下一页");
		 else out.println("<a class=blue3 href=\"manager.jsp?pageno=0\">下一页</a>");%>
              </td>
            </tr>
          </form>
          
        </table>
</Content>
<PostDateTime>2002-6-2 14:24:32</PostDateTime>
</Reply>
<Reply>
<PostUserNickName>紫剑伊</PostUserNickName>
<rank>四级(中级)</rank>
<ranknum>user4</ranknum>
<credit>100</credit>
<ReplyID>5028305</ReplyID>
<TopicID>771284</TopicID>
<PostUserId>116191</PostUserId>
<PostUserName>zijianyi</PostUserName>
<Point>5</Point>
<Content>xuehong_BP(恶泓) :
要先用
Rst=Stmt.executeQuery("select count(*) from table");
Rst.next();
int num=Rst.getInt(1);
得到个数
然后再逐个显示
Rst=Stmt.executeQuery("select * from table");
while(Rst.next())
{
}
</Content>
<PostDateTime>2002-6-2 17:42:04</PostDateTime>
</Reply>
<Reply>
<PostUserNickName>saintKnight</PostUserNickName>
<rank>五级(中级)</rank>
<ranknum>user5</ranknum>
<credit>100</credit>
<ReplyID>5029832</ReplyID>
<TopicID>771284</TopicID>
<PostUserId>237709</PostUserId>
<PostUserName>saintKnight</PostUserName>
<Point>10</Point>
<Content>java.sql.ResultSet rs= Stmt.executeQuery(sql);
sun.jdbc.rowset.CachedRowSet crs=new CachedRowSet();
crs.populate(rs);
将ResultSet转换成CachedRowSet类型就可以使用size()方法了</Content>
<PostDateTime>2002-6-2 20:25:03</PostDateTime>
</Reply>
<Reply>
<PostUserNickName>恶泓</PostUserNickName>
<rank>一级(初级)</rank>
<ranknum>user1</ranknum>
<credit>100</credit>
<ReplyID>5036559</ReplyID>
<TopicID>771284</TopicID>
<PostUserId>116705</PostUserId>
<PostUserName>xuehong_BP</PostUserName>
<Point>0</Point>
<Content>多谢goldsoft(chiwp), zijianyi(紫剑伊) ,JK_10000,saintKnight(saintKnight) 等仁兄的帮助,saintKnight可能要高版本才有,Rs.absolute()方法出现错误,rs只能向前。
东西已经搞出来了。</Content>
<PostDateTime>2002-6-3 11:29:49</PostDateTime>
</Reply>
</Replys>
</Topic>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -