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
# 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);
}
}
# 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