|
Slide 4.3: Record management systems Slide 4.5: Programming with the RMS (cont.) Home |
|
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.
import javax.microedition.rms.*;
RecordStore rs = null;
try {
rs = RecordStore.openRecordStore( "myDBfile", true );
}
catch( RecordStoreNotFoundException e ) {
// doesn't exist
}
catch( RecordStoreException e ) {
// some other error
}
It creates a new database file named myDBfile.
The second parameter, which is set to true, says that if the record store does not exist, create it.
byte[ ] data = new byte[2];
data[0] = 0; data[1] = 1;
try {
int id = rs.addRecord( data, 0, data.length );
}
catch( RecordStoreFullException e ) {
// no room left for more data
}
catch( RecordStoreNotOpenException e ) {
// store has been closed
}
catch( RecordStoreException e ) {
// general error
}