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();
}
}