Rms

Actually Usage of Record Management Store in J2me applications , i know , but now its not working .

i.e., records are not stored , every time newly added records only saved

i have uninstalled the Netbeans 5.5 & tried by installing once again ,

eventhough i got same problem of no Persistence .

can anyone suggest me how to save rms records .........

Regards,

Vasu

[412 byte] By [vasuvuggu@gmail.coma] at [2007-11-27 4:57:30]
# 1

cHECK THIS CODE....

import javax.microedition.rms.*;

import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

import javax.microedition.io.*;

public class OpenClose extends MIDlet

{

private RecordStore rs = null;

static final String RECORD_STORE = "rms_test";

public OpenClose()

{

// Open the record store

openRMS();

// Write to the record store

writeRMS("Java 2 Micro Edition");

writeRMS("Core J2ME Technology");

readRMS();// Read from the record store

closeRMS();// Close record store

deleteRMS(); // Delete record store

}

public void destroyApp( boolean unconditional )

{

}

public void startApp()

{

destroyApp(false);

notifyDestroyed();

}

public void pauseApp()

{

}

public void openRMS()

{

try

{

// Create the record store if it does not exist

rs = RecordStore.openRecordStore(RECORD_STORE, true );

}

catch (Exception e)

{

db(e.toString());

}

}

public void closeRMS()

{

try

{

rs.closeRecordStore();

}

catch (Exception e)

{

db(e.toString());

}

}

public void deleteRMS()

{

if (RecordStore.listRecordStores() != null)

{

try

{

RecordStore.deleteRecordStore(RECORD_STORE);

}

catch (Exception e)

{

db(e.toString());

}

}

}

public void writeRMS(String str)

{

byte[] rec = str.getBytes();

try

{

rs.addRecord(rec, 0, rec.length);

}

catch (Exception e)

{

db(e.toString());

}

}

public void readRMS()

{

try

{

byte[] data = new byte[50];

int dataLen;

System.out.println("Reading from the record store:\n");

for (int i = 1; i <= rs.getNumRecords(); i++)

{

System.out.println("");

dataLen = rs.getRecord(i, data, 0);

System.out.println("Record #" + i + ": " + new String(data, 0, dataLen));

}

System.out.println("");

}

catch (Exception e)

{

db(e.toString());

}

}

/*--

* Message to console for debug/errors

*-*/

private void db(String str)

{

System.err.println("Msg: " + str);

}

}

anup123a at 2007-7-12 10:12:59 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2

Hi

First of all thakyou to respond ,

anyway i have tried this code also , every time newly added records are only available ,[ by displaying those records i know that ]

but after closing that application , after restaring that application also we have to get those old added records , but actually old records r not available to me , actually where these records are stored can u tel me?

Otherwise can u tel me any alternative to this one?

Regards,

Vasu

vasuvuggu@gmail.coma at 2007-7-12 10:12:59 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3

Hi,

See when you store the records it gets stored in the RMS memory of the mobile. This records are get stored in the record store name. when you create any record store u r giving the name to that record store and write the records in that record store. And when u want to read this records u have to again open that record store and read the records.

Check the code i have given and try it out its so simple. And if any problem i will explain it to you in the code....

regards,

Anup .

anup123a at 2007-7-12 10:12:59 > top of Java-index,Java Mobility Forums,Java ME Technologies...