-2

How can I create multiple columns in rms?

Like Name, Occupation etc.

I have just used RMS built-in functions like addRecord. I haven't found any way to create multiple columns except for concatenate all the column values in one string add pass it to addRecord

gnat
  • 6,213
  • 108
  • 53
  • 73
  • 2
    You have to elaborate your question, show what you have tried, etc – adarshr Feb 07 '12 at 09:27
  • I have just use RMS built-in Functions like addRecord ....i havent find any way to creat multiple Colunms except cocatenate all the colunm values in one string add pass it to addRecord – user1194148 Feb 07 '12 at 09:32

2 Answers2

2

Create a csv-like String containing all the column data you want :

String row = "nameData;occupationdata;";

Then invoke this method :

public synchronized int addRecord(String record) {
        // Convert the string record to an array of bytes
        byte[] bytes = record.getBytes();
        // Add the byte array to the record store
        try {
            return recordStore.addRecord(bytes, 0, bytes.length);
        }
        catch (RecordStoreException e) {
            e.printStackTrace();
        }
        return -1;
    }

So you know in advance that the first part is for name value, second part is for occupation value.

pheromix
  • 18,213
  • 29
  • 88
  • 158
2

Generally RMS is unStructured Type of Data Storage in Java ME. So RMS Stores Data like in Flat File kind format. This is the reason RMS you can not perform query operations in RMS.

Now Coming to your point, To store Data with Multiple Columns, you can do it in following two ways.

  • XML Based

    For XML Base, you need to give XML tags to your data for example in your case,

<ROW><NAME>Lucifer</NAME><OCCUPATION>Student</OCCUPATION><AGE>21</AGE></ROW>

Now you can store this XML in RMS, and while retriving data, you need to parse it such that it will return you column base value.

  • Using some Delimiters in Records ( for e.g. "|" Pipe Sign )

    For Another option you can simply add "|" sign after each value for example in your case,

 Lucifer|Student|21|
 Rajan|Student|20|

Now while retrieving data , you need to parse this "|" sign and fetch various data from one column.

Lucifer
  • 29,392
  • 25
  • 90
  • 143