java blog

          java boy

          常用鏈接

          統(tǒng)計(jì)

          最新評(píng)論

          記錄庫(kù)操作工具類(lèi)


          import javax.microedition.rms.InvalidRecordIDException;
          import javax.microedition.rms.RecordStore;
          import javax.microedition.rms.RecordStoreException;
          import javax.microedition.rms.RecordStoreFullException;
          import javax.microedition.rms.RecordStoreNotFoundException;
          import javax.microedition.rms.RecordStoreNotOpenException;


          public class RecordStoreUtil {
          public RecordStore openARecondStore(String rsname){
              RecordStore rs=null;
              if(rsname.length()>32) return null;
              try{
                   rs=RecordStore.openRecordStore(rsname,true);
              }catch(RecordStoreFullException notFoundException){

              }catch(RecordStoreNotFoundException notFoundException){

              }catch(RecordStoreException notFoundException){

              }finally{
                  return rs;
              }
          }
          public RecordStore openARecordStoreExisted(String rsname){
              RecordStore rs=null;
              if(rsname.length()>32)return null;
             try{
                   rs=RecordStore.openRecordStore(rsname,false);
              }catch(RecordStoreFullException notFoundException){

              }catch(RecordStoreNotFoundException notFoundException){

              }catch(RecordStoreException notFoundException){

              }finally{
                  return rs;
              }
          }
           //刪除
          public static boolean delRecordStore(String rsname){
              //
              if(rsname.length()>32)return false;
              //

             try{
                 RecordStore.deleteRecordStore(rsname);

             }catch(Exception e){
                 return false;
             }
              return true;
          }
          //添加
          public static int writeString(RecordStore rs,String myString){
              byte[] b=myString.getBytes();
              int id=-1;
              try{
                  id=rs.addRecord(b, 0, b.length);

              }catch(Exception e){
                  //
             
          }
              return id;
          }

          //獲取
          public static String getString(RecordStore rs,int id){
                  try {
                      byte[] b = rs.getRecord(id);
                      return (new String(b));
                  } catch (RecordStoreNotOpenException ex) {
                      ex.printStackTrace();
                  } catch (InvalidRecordIDException ex) {
                      ex.printStackTrace();
                  } catch (RecordStoreException ex) {
                      ex.printStackTrace();
                  }
                  return null;

          }
          //修改
          public static void setString(RecordStore rs,int id,String newString){
              byte[] b=newString.getBytes();
                  try {
                      rs.setRecord(id, b, 0, b.length);
                  } catch (Exception ex) {

                  }
          }
          //添加證書(shū)數(shù)據(jù)記錄
          public static int writeInt(RecordStore rs,int myInt){
              int id=-1;
              String myString=(new Integer(myInt)).toString();
              id=writeString(rs,myString);
              return id;
          }
          //獲取
          public static int getInt(RecordStore rs,int id){
              int result=Integer.MAX_VALUE;
              String s=getString(rs,id);
              try{
              result=Integer.parseInt(s);
              }catch(Exception e){

              }
              return result;
          }
          //修改
          public static void setInt(RecordStore rs,int newInt){
              String myString=(new Integer(newInt)).toString();
          }

           

           

           

           


          }

          posted on 2009-12-10 19:09 javaz 閱讀(284) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): javaME


          只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 麦盖提县| 石阡县| 宁乡县| 名山县| 隆子县| 乌审旗| 健康| 景德镇市| 北票市| 南丹县| 长寿区| 策勒县| 怀安县| 阿拉善盟| 永吉县| 淳安县| 集安市| 龙井市| 高密市| 九台市| 金寨县| 兴安盟| 隆子县| 延津县| 怀安县| 绥阳县| 石城县| 拜城县| 浏阳市| 互助| 河池市| 军事| 怀远县| 临高县| 龙山县| 略阳县| 鸡泽县| 友谊县| 托克逊县| 镇江市| 龙岩市|