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

📄 jdk1.5学习之rowset(一).htm

📁 Sun的高速缓存CachedRowSet方案资料档
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<P id=hijpqktrcajgvvbgip>o]业络9教中V无6]垠$络.C1管</P>而且他是无连接的</SPAN><SPAN 
lang=EN-US><FONT face="Times New Roman">RowSet</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的其他</SPAN><SPAN 
lang=EN-US><FONT face="Times New Roman">3</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个实现的父接口,也就是说其他</SPAN><SPAN 
lang=EN-US><FONT face="Times New Roman">3</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个接口都直接或者间接继承了它。从名字我们可以知道,它的原理就是读入数据保存在缓存进行相应的操作。</SPAN></FONT>
<P></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=3><SPAN 
lang=EN-US><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp; 
</SPAN><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; 
</SPAN></FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">创建接口对象除了上面的两种创建方式,还有一个方法,就是在构造方法里面传递一个</SPAN><SPAN 
lang=EN-US><FONT face="Times New Roman">SyncProvider</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。之前我说过无连接的</SPAN><SPAN 
lang=EN-US><FONT face="Times New Roman">RowSet</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">都是基于流读写的,那么这里所说的</SPAN><SPAN 
lang=EN-US><FONT face="Times New Roman">SyncProvider</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">就是提供了特定的</SPAN><SPAN 
lang=EN-US><FONT face="Times New Roman">Reader</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN 
lang=EN-US><FONT face="Times New Roman">Writer</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</SPAN><SPAN 
lang=EN-US><FONT face="Times New Roman">jdk1.5</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文档的</SPAN><SPAN 
lang=EN-US><FONT face="Times New Roman">Sample Coder</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">有这样的实现:</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT 
face="Times New Roman"><FONT size=3><SPAN 
style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>String 
provider= “com.fred.providers.HighAvailabilityProvider”</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT 
face="Times New Roman"><FONT size=3><SPAN style="mso-spacerun: yes">&nbsp; 
</SPAN><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>CachedRowSet 
crs=new CachedRowSetImpl(provider);</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=3><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这样我们就为</SPAN><SPAN 
lang=EN-US><FONT face="Times New Roman">RowSet</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设置了特定的</SPAN><SPAN 
lang=EN-US><FONT face="Times New Roman">Reader</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN 
lang=EN-US><FONT face="Times New Roman">Writer</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,但是这是需要第三方的包支持的。而我们使用无参的构造方法创建的对象是使用了默认的</SPAN><SPAN 
lang=EN-US><FONT face="Times New Roman">SyncProvider</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,当然一般来说这对于我们就已经足够了。创建了对象之后就可以使用和</SPAN><SPAN 
lang=EN-US><FONT face="Times New Roman">JdbcRowSet</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一样的方法来进行就结果集的增删改操作了,但是唯一不同的就是在更新了结果集之后必须调用</SPAN><SPAN 
lang=EN-US><FONT face="Times New Roman">Writer</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">将缓存中的数据写入数据库,而其方法就是</SPAN><SPAN 
lang=EN-US><FONT 
face="Times New Roman">crs.acceptChages();</FONT></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=3><SPAN 
lang=EN-US><FONT face="Times New Roman"><SPAN 
style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN>CachedRowSet</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">提供的最令人兴奋的功能就是分页功能。以前程序员很头疼的问题就是怎么处理数据分页而不影响性能,
<DIV id=iwrlqoaghckev>MvmF+业y育:U&amp;Tk</DIV>现在有了</SPAN><SPAN lang=EN-US><FONT 
face="Times New Roman">CachedRowSet</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一切都变得那么简单,请看下面的代码:</SPAN></FONT>
<P></P>
<P class=MsoNormal 
style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.75pt; TEXT-ALIGN: left; mso-layout-grid-align: none" 
align=left><SPAN lang=EN-US><FONT face="Times New Roman" size=3>CachedRowSet 
crs=new CaehedRowSetImpl();</FONT></SPAN></P>
<P class=MsoNormal 
style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.75pt; TEXT-ALIGN: left; mso-layout-grid-align: none" 
align=left><SPAN lang=EN-US><FONT face="Times New Roman" 
size=3>crs.setUrl(“jdbc:mydql://localhost:3306/test”);</FONT></SPAN></P>
<P class=MsoNormal 
style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.75pt; TEXT-ALIGN: left; mso-layout-grid-align: none" 
align=left><SPAN lang=EN-US><FONT face="Times New Roman" 
size=3>crs.setUsername(“root”);</FONT></SPAN></P>
<P class=MsoNormal 
style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.75pt; TEXT-ALIGN: left; mso-layout-grid-align: none" 
align=left><SPAN lang=EN-US><FONT face="Times New Roman" 
size=3>crs.setPassword(“”);</FONT></SPAN></P>
<P class=MsoNormal 
style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.75pt; TEXT-ALIGN: left; mso-layout-grid-align: none" 
align=left><SPAN lang=EN-US><FONT face="Times New Roman" 
size=3>crs.setCommand(“select * from table<CHMETCNV w:st="on" tcsc="0" 
numbertype="1" negative="False" hasspace="False" sourcevalue="1" 
unitname="”">1”</CHMETCNV>);</FONT></SPAN></P>
<P class=MsoNormal 
style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.75pt; TEXT-ALIGN: left; mso-layout-grid-align: none" 
align=left><SPAN lang=EN-US><FONT face="Times New Roman" 
size=3>crs.setPageSize(5);</FONT></SPAN></P>
<P class=MsoNormal 
style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.75pt; TEXT-ALIGN: left; mso-layout-grid-align: none" 
align=left><SPAN lang=EN-US><FONT face="Times New Roman" 
size=3>crs.execute();</FONT></SPAN></P>
<P class=MsoNormal 
style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.75pt; TEXT-ALIGN: left; mso-layout-grid-align: none" 
align=left><SPAN lang=EN-US><FONT face="Times New Roman" 
size=3>while(crs.nextPage()) </FONT></SPAN></P>
<P class=MsoNormal 
style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.75pt; TEXT-ALIGN: left; mso-layout-grid-align: none" 
align=left><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=3><SPAN 
style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN>while(crs.next()) </FONT></FONT></SPAN></P>
<P class=MsoNormal 
style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.75pt; TEXT-ALIGN: left; mso-layout-grid-align: none" 
align=left><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=3><SPAN 
style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN>System.out.println(crs.getInt(“id”+”\t\t”+crs.getString(“name”));</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=3><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们在</SPAN><SPAN 
lang=EN-US><FONT face="Times New Roman">crs.execute()</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">之前设置每页的数据行数,那么</SPAN><SPAN 
lang=EN-US><FONT face="Times New Roman">Reader</FONT></SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">读取数据的时候就只读指定的行数的数据,这样我们就避免了一次读取所有数据再进行分页操作。是不是很简单呢?</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=3><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=3><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
to be continued....</SPAN></FONT></P></SPAN></SPAN>
<DIV style="TEXT-ALIGN: center"></DIV>
<DIV style="TEXT-ALIGN: center">
<DIV>
<SCRIPT type=text/javascript><!--
google_ad_client = "pub-5759554067406384";
google_alternate_color = "FFFFff";
google_ad_width = 468;
google_ad_height = 15;
google_ad_format = "468x15_0ads_al";
//2007-03-13: Link
google_ad_channel = "1768726088";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "003366";
google_color_text = "000000";
google_color_url = "000000";
//--></SCRIPT>

<SCRIPT src="jdk1.5学习之RowSet(一).files/show_ads.js" type=text/javascript>
</SCRIPT>
</DIV><BR><A id=ctl00_ContentPlaceHolder1_pager_ctl01_HyperLink2 
href="http://www.5inet.net/Develop/Java/034593,jdk1dot5HuaXiZhiRowSet(Yi)_1.aspx">第1页</A> 
</DIV>
<P align=center><A id=ctl00_ContentPlaceHolder1_hlReview 
href="http://www.5inet.net/review.ashx/12/28076/34593/">进入论坛发表/查看评论</A></P>
<P><A id=ctl00_ContentPlaceHolder1_hlPrev 
href="http://www.5inet.net/Develop/Java/034592,TomcatXiajavaDeXuNiNaCunDiaoZheng(YuanChuang).aspx">上一篇:Tomcat下java的虚拟内存调整(原创)</A><BR><A 
id=ctl00_ContentPlaceHolder1_hlNext 
href="http://www.5inet.net/Develop/Java/034594,NHibernate(one-to-many)DeWenDi.aspx">下一篇:NHibernate(one-to-many)的问题</A> 
</P></DIV><BR></DIV></DIV>
<DIV id=splitter></DIV>
<DIV id=PageRegion2>
<DIV class=parent>
<H2><A href="http://bbs.5inet.net/index.aspx">无垠论坛最新主题</A></H2>
<DIV class=child2>
<UL>
  <LI><A href="http://bbs.5inet.net/topic.aspx?topicid=166372" 
  target=_blank>[评论]linux ISDN常见故障及排除</A>
  <LI><A href="http://bbs.5inet.net/topic.aspx?topicid=166370" 
  target=_blank>[评论]美TiVo力推新型弹出式广告及刻录限制方式惹争议...</A>
  <LI><A href="http://bbs.5inet.net/topic.aspx?topicid=166371" 
  target=_blank>[评论]国产软件的红与黑 国产软件出路在哪?</A>
  <LI><A href="http://bbs.5inet.net/topic.aspx?topicid=166366" 
  target=_blank>[评论]周三早盘纳斯达克中国概念股全线上涨</A></LI></UL></DIV></DIV>
<DIV class=parent>
<H2><A href="http://www.5inet.net/WanLan/Default.aspx">网络管理</A></H2>
<DIV class=child2>
<UL>
  <LI><A 
  href="http://www.5inet.net/WanLan/NetworkAdministrator/NetworkSkills/003042,ChaDeBuDangCaoChengWangSuHuanMan.aspx">接地不当造成网速缓慢</A>
  <LI><A 
  href="http://www.5inet.net/WanLan/QQ/042224,WangZhanLouDongBaiChu_QQMiMa_DaBaiTianXia_.aspx">网站漏洞百出 
  QQ密码“大白天下”</A>
  <LI><A 
  href="http://www.5inet.net/WanLan/NetworkAdministrator/077168,ShenMaShiDaiLiARP(proxy_ARP)_.aspx">什么是代理ARP(proxy 
  ARP)?</A>
  <LI><A 
  href="http://www.5inet.net/WanLan/NetworkAdministrator/NetworkBase/001509,kernel_hackingJianChanRuMen.aspx">kernel 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -