J2ME game using records management system to save and read the highest record

Source: Internet
Author: User

Records Management systems (record Management system, abbreviation RMS). He can enable you to store data in the memory of your mobile device in a persistent manner.

I. Records Management System Overview

The records management system is simply a small database. A typical structure model of a database. RMS provides a RecordStore class for MIDlet applications and RMS communications. RecordStore is equivalent to a table in the database. We can place several records (record) in each table, each containing two columns of data. As shown in the following illustration:

Each record store stored in RMS is associated with a MIDlet suite (a suite is a jar file that can include multiple MIDlet classes). And there is a filename to identify him.

Each record in the record store has only two columns of tables, where the first column is an int-type Integer that represents the ID of the record, and the other column records the data with a byte array table. The record number can be thought of as the primary key of the datasheet. Whether you are storing strings or integers, they are either read from a record or written to a record in byte array.

Second, in-depth RecordStore class

In the MIDP API, the Javax,microedition.rms package is used to support RMS. This package provides a RecordStore class and several interfaces to support the creation and operation of record-dropping stores. The RecordStore class provides a programmable interface for a single record store, making it easy to read and write to a record store.

Use steps:

1, open or create a record store.

2. Read the data from the record store or write the data to the record store.

3, close the record store.

Some of the most common methods are:

openRecordStore()打开一个记录存储,以便读出或写入数据。
getNumRecords()获得纪录存储中记录的数目。
getRecordSize()获得一条记录的数据大小。
getRecord()从一个单独的纪录中获得数据。
addRecord()向一个记录存储添加一条记录的数据。
deleteRecord()删除一条的纪录。
deleteRecordStore()删除整个记录存储。
closeRecordStore()关闭一个记录存储。

Before you use the Record store, you create a RecordStore object. Examples are as follows:

RecordStore rs = null;

To open a record store, you can use the RecordStore object to invoke the Openrecordstore () method to implement:

try{
rs = RecordStore .openRecordStore(“somename” , false );
}
catch( Exception e){
System.err.println(“Failed opening record store !”) ;
}

The first parameter of the Openrecordstore method is the name of the record store, and the second parameter indicates whether a new record store should be created if the record store for the specified name does not exist. If this argument is true, it means that when the record store for the specified name does not exist, a new record store with the same name can be created and opened, false to open only existing record stores, and no record stores are created.

You can determine whether a record store has been successfully opened by using the record you created earlier.

Here we can write a record to the Open Record store:

try{
rs.addRecord(redordData, 0 , recordData.length);
}
catch ( Exception e ){
System.err.println( “ Failed writhing to record store ! ”);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.