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

📄 771284.xml

📁 论坛精华帖子
💻 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&#32;count(*)&#32;from&#32;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&#32;count(*)&#32;from&#32;table");
Rst.next();
int&#32;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(紫剑伊)&#32;仁兄的例子我已经在前面的贴子看了。
我的意思是问:
Rst=Stmt.executeQuery("select&#32;*&#32;from&#32;table&#32;where&#32;a&gt;b");后
Rst内有没有方法可以获得它的纪录条数?num=Rst.get****&#32;这种方法。
</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(紫剑伊)&#32;兄的方式得到总笔数,再把你要显示出的资料select出来:
例如:每页20笔,你要显示第三页,用:select&#32;top&#32;60&#32;*&#32;from&#32;tableName&#32;where&#32;………</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>&#9;int&#32;PageSize=15;&#32;//设置每张网页显示两条记录
&#9;int&#32;ShowPage=1;&#32;//设置欲显示的页数
&#9;int&#32;RowCount=0;&#32;//记录数目
&#9;int&#32;PageCount=0;&#32;//分页后的总页数
strSQL="select&#32;*&#32;from&#32;aaa";
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;Rs=Stmt.executeQuery(strSQL);
&#9;if(Rs.last()){
&#9;&#9;RowCount=Rs.getRow();
&#9;&#9;PageCount=((RowCount%PageSize)==0?(PageCount/PageSize):(RowCount/PageSize)+1);
&#9;&#9;String&#32;PageNo=request.getParameter("pageno");
&#9;&#9;if(PageNo!=null){
&#9;&#9;&#9;rc=Integer.parseInt(PageNo);
&#9;&#9;&#9;if(rc&gt;0)ShowPage=rc;
&#9;&#9;&#9;else&#32;{
&#9;&#9;&#9;&#9;if(rc&lt;0)ShowPage--;
&#9;&#9;&#9;&#9;else&#32;ShowPage++;
&#9;&#9;&#9;}
&#9;&#9;&#9;if(ShowPage&lt;1)ShowPage=1;
&#9;&#9;&#9;if(ShowPage&gt;PageCount)ShowPage=PageCount;
&#9;&#9;}
&#9;&#9;Rs.absolute((ShowPage-1)*PageSize+1);
&#9;}
&#9;else&#32;{
&#9;&#9;RowCount=0;
&#9;&#9;PageCount=0;
&#9;}
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;table&#32;height=25&#32;cellspacing=0&#32;cellpadding=0&#32;width=280&#32;border=0&gt;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;form&#32;name=form2&#32;action=""&#32;method=post&gt;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;tr&gt;&#32;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;td&#32;class=blue3&#32;align=middle&#32;height=28&gt;共&lt;%=PageCount%&gt;页&#32; &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;select&#32;&#32;&#32;&#32;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;onChange=onSelectOption(document.form2.pageno);&#32;name=papeno&gt;
&#9;&#9;&lt;%for(i=1;i&lt;=PageCount;i++){
&#9;&#9;&#9;if(i==ShowPage)out.println("&lt;option&#32;value="+i+"&#32;selected&gt;"+i+"&lt;/option&gt;");
&#9;&#9;&#9;else&#32;out.println("&lt;option&#32;value="+i+"&gt;"+i+"&lt;/option&gt;");
&#9;&#9;}
&#9;&#9;%&gt;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;/select&gt;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32; 第&lt;%=ShowPage%&gt;页 &#32;
&#9;&#9;&lt;%if(ShowPage==1)out.println("上一页");
&#9;&#9;&#32;else&#32;out.println("&lt;a&#32;class=blue3&#32;href=\"manager.jsp?pageno=-1\"&gt;上一页&lt;/a&gt;");%&gt;
&#9;&#9;&lt;%if(ShowPage&gt;=PageCount)out.println("下一页");
&#9;&#9;&#32;else&#32;out.println("&lt;a&#32;class=blue3&#32;href=\"manager.jsp?pageno=0\"&gt;下一页&lt;/a&gt;");%&gt;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;/td&gt;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;/tr&gt;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;/form&gt;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&lt;/table&gt;

</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(恶泓)&#32;:

要先用
Rst=Stmt.executeQuery("select&#32;count(*)&#32;from&#32;table");
Rst.next();
int&#32;num=Rst.getInt(1);
得到个数
然后再逐个显示
Rst=Stmt.executeQuery("select&#32;*&#32;from&#32;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&#32;rs=&#32;Stmt.executeQuery(sql);
sun.jdbc.rowset.CachedRowSet&#32;crs=new&#32;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),&#32;zijianyi(紫剑伊)&#32;,JK_10000,saintKnight(saintKnight)&#32;等仁兄的帮助,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 + -