JR 精品文章 - J2ME中RMS的使用解析(三)
AD: jr (at) javaresearch.org


首页 | 动态 | 文章 | FAQ  | 新闻 | 下载 | 代码 | 工作 | 调查 | 术语 | 站点 | 图书 | 论坛 | 帮助 | 全部  

TOP | 交流 | 软件 | 专栏 | 开源 | 译/著 | 源码 | API  | 推荐 | FTP  | 积分 | 统计 | 搜索 | Blog | 我们  
首页 » 研究文集 » J2ME综合 搜索标题相关文章 搜索标题相关文章    评论此文章 发表评论     开始监控此文章 开始监控   加入收藏夹  加入收藏夹
J2ME中RMS的使用解析(三)
lu_-yi 原创   更新:2007-01-11 19:54:43  版本: 1.0   

public static Appointment getRecord(String name, int j) {//根据记录编号(参数 int j)取得一条记录 
Appointment result = new Appointment(); 

try { 
RecordStore rs = RecordStore.openRecordStore(name, false); 
RecordEnumeration re = rs.enumerateRecords(null, null, false); 
result = new Appointment(rs.getRecord(j)); 
rs.closeRecordStore(); 
} catch (Exception e) { 


return result; 


public static int getIndex(String name, String content) {//得到记录号int j,这里需要使用保留字段str1 
RecordStore rs = null; 
RecordEnumeration re = null; 

try { 
rs = RecordStore.openRecordStore(name, false); //open 
re = rs.enumerateRecords(null, null, false); //enumeration 

for (int i = 0; i < RMS.getNumOfRecords(name); i++) { 
int j = re.nextRecordId(); 
Appointment app = new Appointment(rs.getRecord(j)); 

if (app.getStr1().equals(content)) { 
return j; 


} catch (Exception e) { 
}
return 1; 


public static boolean setRecord(String name, int id, int int1, int int2,//设置记录号为id的记录 
long long1, String str1, String str2, String str3, boolean b) { 
boolean success = false; 
RecordStore rs = null; 
RecordEnumeration re = null; 

try { 
rs = RecordStore.openRecordStore(name, false); //open 
re = rs.enumerateRecords(null, null, false); //enumeration 

Appointment app = new Appointment(int1, int2, long1, str1, str2, str3, b); 
//str1作为保留字段,在这里如此操作:例如若int1为我们设定的关键字,那么str1 = Integer.toString(int1); 

byte[] data = app.toBytes(); 
rs.setRecord(id, data, 0, data.length); 
success = true; 
rs.closeRecordStore(); 
} catch (Exception e) { 


return success; 


在这个类中,我没有将各个Exception向外抛出,一般来说这样作是不合适的,它违背了Java的异常处理机制。但是在我使用这个类的各个J2ME程序中,它是可以胜任的,所以也就没有进行进一步的修改。 
有了以上的两个类和你对RMS的理解,在程序中,你就可以顺畅的使用RMS了。 
比如在MIDlet开始时,如下操作(增加记录): 
protected void startApp() throws MIDletStateChangeException { 
if (RMS.getNumOfRecords(rsName) = = 0) {//rsName在前面已经声明了。String rsName=“MyRMS”; 
for (int i = 0; i <6; i++) { 
RMS.addRecord(rsName, RMS.Int1, i, RMS.Long1, Integer . toString(i), RMS.Str2, "1234567890123456789",false); 

}它就在RMS中增加了6条记录,其中int1,long1,str2,WroteFlag都没有使用,我们只是使用int2,str1(作为保留字段)和str3。 




版权声明   给作者写信
本篇文章对您是否有帮助?  投票:         投票结果:     7       0
作者其它文章: 作者全部文章
评论人:singsongzw 发表时间: Wed Mar 07 18:25:55 CST 2007
小弟在顶一次

这个文章共有 1 条评论
主题: J2ME 上一篇文章
返回文章列表 返回〔J2ME综合〕
下一篇文章 主题: J2ME中RMS的使用解析(二)


文字广告链接
        自主、快速定制基于JAVA的B/S业务系统          重量级企业在线自定义WEB报表平台
        Excel制表、零代码发布、打印、图表结合——快逸报表,免费、稳定、功能强大的java工具
        技术圈: 关于Java、dotNet、PHP、Ruby、奇客、Web2.0等更多资讯博客精选文章

关于 JR  |  版权声明  |  联系我们 

©2002-2006 JR 版权所有 沪ICP备05019622号