您的位置:程序门 -> 移动平台 -> 开发应用



rms实现数据的存储和查询问题(给高分)


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


rms实现数据的存储和查询问题(给高分)[无满意答案结贴,结贴人:wcyjke]
发表于:2007-05-21 20:56:29 楼主

我想写个手机号码归属地(离线查询)的软件,只是如何建立号码数据库的方法不懂。        
我应该怎么输入庞大的号码数据呢??
下面有两个程序,能否帮忙测试一下对不对?(我在eclipse里测试程序没什么错误,但是不懂如何实现这两个程序的交互)
如何对的话,我能否用第一个程序把数据都写入recordstore,然后用第二个程序进行查询呢?

刚学j2me,希望得到你的指导,谢谢!
送分50
****************************************************

import   javax.microedition.midlet.midlet;
import   javax.microedition.rms.*;
import   java.io.*;

public   class   addemployee   extends   midlet   {
  recordstore   rs=null;



public   addemployee(){

}


  public   void   startapp()   throws   midletstatechangeexception{

  try{
//打开新记录存储
rs=recordstore.openrecordstore( "employeeinfp ",   true);
//写入信息
writers(1300010, "北京 ", "北京 ");
writers(1300012, "天津 ", "天津 ");
writers(1300020, "上海 ", "上海 ");
writers(1365733, "湖南 ", "株洲 ");
writers(1365854, "贵州 ", "黔南州 ");
writers(1365909, "四川 ", "广安 ");
writers(1365960, "广西 ", "南宁 ");
writers(1366261, "广东 ", "深圳 ");
writers(1366361, "山西 ", "太原 ");
writers(1366399, "河南 ", "南洋 ");
writers(1366537, "山东 ", "济南 ");
}

catch(exception   e){
system.out.println(e);
}
finally{
//关闭记录存储
try{
rs.closerecordstore();
}
catch(exception   e){

system.out.println(e);
}
}
  }
 
 
public   void   pauseapp(){

}
public   void   destroyapp(boolean   unconditional){

notifydestroyed();

}
/**
*定义一个方法用于增加雇员信息
**/
public   void   writers(int   num,string   provice,string   city){

try{


bytearrayoutputstream   baos=new   bytearrayoutputstream();
dataoutputstream   dos=new   dataoutputstream(baos);
dos.writeint(num);
dos.writeutf(provice);
dos.writeutf(city);
//关闭流
baos.close();
dos.close();
byte   rec[]=baos.tobytearray();
try{
rs.addrecord(rec,0,rec.length);

}
catch(exception   e){

system.out.println(e);
}
}
  catch(ioexception   ioe){
  system.out.println(ioe);
  }
  }
}

*******************************************************
************************************************************************
import   javax.microedition.midlet.midlet;
import   javax.microedition.lcdui.*;
import   javax.microedition.rms.*;
import   java.io.*;

public   class   searchemployee   extends   midlet  
                            implements   commandlistener{
private   display   display;
private   alert   alert;
private   form   form;
private   command   start;
private   command   exit;
private   textfield   textfield;
private   recordstore   recordstore=null;
private   recordenumeration   recordenumeration=null;
private   filter   filter=null;
private   searchemployee(){
display=display.getdisplay(this);
start=new   command( "start ",command.screen,1);
exit=new   command( "exit ",command.screen,1);
textfield=new   textfield( "number: ", " ",10,textfield.any);
form=new   form( "请输入要查询号码的前七位! ");
form.addcommand(exit);
form.addcommand(start);
form.append(textfield);
form.setcommandlistener(this);
}
public   void   startapp(){
display.setcurrent(form);
}
public   void   pauseapp(){
}
public   void   destroyapp(boolean   uncondition){
}

public   void   commandaction(command   command,displayable   displayable){
if(command==exit){
destroyapp(false);
notifydestroyed();
}
else   if(command==start){
try{
recordstore=recordstore.openrecordstore( "employeeinfo ",   true);
}
catch   (exception   error){
alert=new   alert( "error   opening ",error.tostring(),null,alerttype.warning);
alert.settimeout(alert.forever);
display.setcurrent(alert);
}
try{
string   inputstring;
byte[]   byteinputdata=new   byte[1000];
bytearrayinputstream   inputstream=
          new   bytearrayinputstream(byteinputdata);
datainputstream   inputdatastream=
          new   datainputstream(inputstream);
if(recordstore.getnumrecords()> 0){
filter   =new   filter(textfield.getstring());
recordenumeration=recordstore.enumeraterecords(filter,   null,   false);
while(recordenumeration.hasnextelement()){
recordstore.getrecord(recordenumeration.nextrecordid(),byteinputdata,0);
inputstring=inputdatastream.readint()+ " "+inputdatastream.readutf()+ " "
                                              +inputdatastream.readutf();
alert=new   alert( "searching ",inputstring,null,alerttype.warning);
alert.settimeout(alert.forever);
display.setcurrent(alert);

}
}
inputstream.close();
}
catch(exception   error){
alert=new   alert( "error   reanding ",error.tostring(),null,alerttype.warning);
alert.settimeout(alert.forever);
display.setcurrent(alert);
}
try{
recordstore.closerecordstore();
}
catch(exception   error){
alert=new   alert( "error   closing ",error.tostring(),null,alerttype.warning);
alert.settimeout(alert.forever);
display.setcurrent(alert);
}
if(recordstore.listrecordstores()!=null){
try{
recordstore.deleterecordstore( "employeeinfo ");
filter.filterclose();
recordenumeration.destroy();
}
catch(exception   error){
alert=new   alert( "error   removing ",error.tostring(),null,alerttype.warning);
alert.settimeout(alert.forever);
display.setcurrent(alert);
}
}
}
}


class   filter   implements   recordfilter{
private   string   search=null;
private   bytearrayinputstream   inputstream=null;
private   datainputstream   datainputstream=null;
public   filter(string   sertchcriteria){
search=sertchcriteria;

}
public   boolean   matches(byte[]   suspect){
string   string;
try{
inputstream=new   bytearrayinputstream(suspect);
datainputstream=new   datainputstream(inputstream);
string=datainputstream.readutf();

}
catch(exception   error){
return   false;
}
if(string!=null   &&   string.indexof(search)!=-1)
return   true;
else
return   false;
}
public   void   filterclose(){
try{
if(inputstream!=null){
inputstream.close();
}
if(datainputstream!=null){
datainputstream.close();

}

}
catch(exception   e){
}
}
}
}


快速检索

最新资讯
热门点击