Programming with the RMS

Database programming with the RMS is relatively straightforward. A record store consists of a collection of records that is uniquely identified by its record ID, which is an integer value. The record ID is the primary key for the records. The first record has an ID of 1, and each additional record is assigned an ID that is the previous value plus 1. The record ID is stored as an integer value, which gives the theoretical limit of 2,147,483,647 records.[10]

Opening, Closing, and Deleting a Record Store

To open a record store, you need to be familiar with the static openRecordStore( ) method of the RecordStore class:

public static RecordStore openRecordStore(String recordStoreName, 
    Boolean createIfNecessary) throws RecordStoreException, 
    RecordStoreFullException, RecordStoreNotFoundException

Here is an example of using this method:

RecordStore db = null;

try {
    db = RecordStore.openRecordStore("myDBfile", true);
} catch (RecordStoreNotFoundException rsnfe) {
    // Handle exception
} catch (RecordStoreFullException fsfe) {
    // Handle exception
} catch (RecordStoreException rse) {
    // Handle exception

Assuming that everything works right, this line of code creates a new database file named myDBfile. The second parameter, a boolean which is set to true, says that if the record store does not exist, then you should create it.


If the openRecordStore( ) method is called by a MIDlet when the record store is already open by another MIDlet in the same MIDlet suite, the ...

Get Wireless Java now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.