Record Management in J2ME

By Manoj Alwis

Happy New Year All My Friends, This is my First J2ME Article in 2010.I’ll give you new and very important J2ME knowledge in this year also. This month article I’ll explain about record management system in J2ME (RMS).
The J2ME record management system (RMS) provides a mechanism through which MIDlets can persistently store data and retrieve it later. Each record store can be visualized as a collection of records, which will remain persistent across multiple invocations of the MIDlet. The device platform is responsible for making its best effort to maintain the integrity of the MIDlet's record stores throughout the normal use of the platform, including reboots, battery changes, etc. A record store is created in platform-dependent locations, like nonvolatile device memory, which are not directly exposed to the MIDlets. Record store implementations ensure that all individual record store operations are atomic, synchronous, and serialized, so no corruption of data will occur with multiple accesses.

  • The javax.microedition.rms.RecordStore class represents a RMS record store. It provides several methods to manage as well as insert, update, and delete records in a record store.
  • To open a record store, the openRecordStore() method of javax.microedition.rms.RecordStore is invoked. public static RecordStore openRecordStore(String recordStoreName, boolean createIfNecessary) opens a record store with the given name recordStoreName.

RecordStore rs = RecordStore.openRecordStore("MyAppointments",true);

  • To Close record store, Once all operations are done, a call to closeRecordStore() closes the record store with the given name. When a record store is closed, it is disabled for further operations.
   Rs.closeRecordStore();

 

  • To delete record store, using deleteRecordStore() Method.
 
RecordStore.deleteRecordStore("MyAppointments");

 

  • To Insert records, the MIDlet invokes the addRecord() method of javax.microedition.rms.RecordStore class to insert a new record into the record store.
String appt = "new record";
byte bytes[] = appt.getBytes();
rs.addRecord(bytes,0,bytes.length);
  • To update existing records, using setRecord () method in RMS
String newappt = "update record";
Byte data = newappt.getBytes();
Rs.setRecord(1, data, 0, data.length());

 

  • To delete one of record in record store , using deleteRecord() method.
Rs.deleteRecord(1);

 

See you next month with another J2ME article. Till then dive in and experiment with your own code to get grip with J2ME.

 

Previous article

 

Share/Save
Your rating: None Average: 3.5 (2 votes)

Post new comment