RecordStore的三种操作用法

//删除地址记录
 public  void deleData(String name){
  try{
   RecordStore rs=RecordStore.openRecordStore(dbname, false);
   RecordEnumeration re=rs.enumerateRecords(null, null, false);
   while(re.hasNextElement()){
    byte tmp[]=re.nextRecord();
    bis=new ByteArrayInputStream(tmp);
    dis=new DataInputStream(bis);
    String rName=dis.readUTF();
    String rTel=dis.readUTF();
    if(rName.equals(name)){
     //根据记录ID删除
     rs.deleteRecord(dis.readInt());
     //显示所有记录
     listAllForm();
    }
   }
   re.destroy();
   rs.closeRecordStore();
  }catch(Exception e){
   System.out.println("Delete Error"+e.getMessage());
  }
  
 }

//向记录存储集中添加记录
 public void addData(){
  String name = txtName.getString();
  String tel= txtTel.getString();
  try{
   RecordStore rs= RecordStore.openRecordStore(dbname, false);
   bos =new ByteArrayOutputStream();
   dos=new DataOutputStream(bos);
   dos.writeUTF(name);
   dos.writeUTF(tel);
   dos.writeInt(rs.getNextRecordID());
   dos.flush();
   byte tmp[]=bos.toByteArray();
   rs.addRecord(tmp, 0,tmp.length);
   rs.closeRecordStore();
   
  }catch(Exception e){
   System.out.println("Add data error:"+e.getMessage());
  }
 }
}
 
// 显示地址记录的详细信息
 public void searchData(String name) {
  Form f = new Form("详细信息");
  Command back = new Command("返回", Command.SCREEN, 1);
  f.addCommand(back);
  f.setCommandListener(this);
  try {
   RecordStore rs = RecordStore.openRecordStore(dbname, false);
   RecordEnumeration re = rs.enumerateRecords(null, null, false);
   while (re.hasNextElement()) {
    byte tmp[] = re.nextRecord();
    bis = new ByteArrayInputStream(tmp);
    dis = new DataInputStream(bis);
    String rName = dis.readUTF();
    String rTel = dis.readUTF();
    if (rName.equals(name)) {
     f.append("Name:/n");
     f.append(rName + "/n");
     f.append("Tel:/n");
     f.append(rTel + "/n");
     display.setCurrent(f);
     return;
    }
   }
   rs.closeRecordStore();
  } catch (Exception e) {
   System.out.println();
  }
 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云雨巫山

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值