//删除地址记录
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 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();
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();
}
}
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();
}
}