O'Reilly logo

Wireless Java by Qusay H. Mahmoud

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

Tip

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required