Troubleshooting guide
75
3: Storing data
Use the MIDP record store
Task Steps
Create a record store. >Invoke openRecordStore() and specify true to indicate that the method should create the record store
if the record store does not exist.
RecordStore store = RecordStore.openRecordStore("Contacts", true);
Add a record. >Invoke addRecord().
int id = store.addRecord(_data.getBytes(), 0, _data.length());
Retrieve a record. >Invoke getRecord(int, byte[], int) and provide the following parameters:
• a record ID
• a byte array
• an offset
byte[] data = new byte[store.getRecordSize(id)];
store.getRecord(id, data, 0);
String dataString = new String(data);
Retrieve all records. 1. Invoke openRecordStore().
RecordStore store = RecordStore.openRecordStore("Contacts", false);
2. Invoke enumerateRecords() with the following parameters:
• filter: specifies a RecordFilter object to retrieve a subset of record store records (if null, the
method returns all records)
• comparator: specifies a RecordComparator object to determine the order in which the method
returns the records (if null, the method returns the records in any order)
• keepUpdated: determines if the method keeps the enumeration current with the changes to the
record store
RecordEnumeration e = store.enumerateRecords(null, null, false);