java blog

          java boy

          常用鏈接

          統計

          最新評論

          2009年12月10日 #

          記錄庫操作工具類


          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) {

                  }
          }
          //添加證書數據記錄
          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 @ 2009-12-10 19:09 javaz 閱讀(284) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 安福县| 苗栗市| 桃园县| 南部县| 文成县| 民乐县| 钟祥市| 固安县| 福建省| 桐梓县| 阿坝| 静乐县| 盱眙县| 丰顺县| 桃园县| 娱乐| 南投县| 六盘水市| 体育| 广宁县| 谷城县| 红桥区| 贡觉县| 玉山县| 安泽县| 康定县| 嘉荫县| 中卫市| 乳山市| 武清区| 宁国市| 雷波县| 瑞安市| 江安县| 彭阳县| 长春市| 泸州市| 富宁县| 昭苏县| 米脂县| 买车|