import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
import java.io.*;
public class RMSDemo extends MIDlet implements CommandListener {
private Display display;
private RecordStore rs=null;
private Command exit;
private RecordEnumeration re;
private int recordNO;
Form frm;
int index=0;
public RMSDemo() {
display = Display.getDisplay(this);
//Create a RMS
try {
rs= RecordStore.openRecordStore("myRecord",false);
rs.closeRecordStore();
} catch(Exception e) {
System.out.println(e);
}
}
public void startApp() {
frm=new Form("RMSDemo");
exit= new Command("Exit",Command.EXIT,1);
frm.addCommand(exit);
add= new Command("Add",Command.SCREN,1);
frm.addCommand(add);
delete= new Command("Delete",Command.SCREEN,2);
frm.addCommand(delete);
show= new Command("SHOW",Command.SCREEN ,3);
frm.addCommand(show);
frm.setCommandListener(this);
frm.append("#####");
display.setCurrent(frm);
}
public void pauseApp() {
}
public void destroyApp(boolean un) {
}
// Handling commands
public void commandAction(Command cmd,Displayable d) {
if(cmd==add) {
addRecord();
} else
if(cmd==delete) {
removeRecord();
} else
if(cmd==show) {
try {
byte b[]= rs.getRecord(recordNO);
String s= new String(b);
frm.append(s);
} catch(Exception e) {}
}
}
void addRecord() {
try {
rs= RecordStore.openRecordStore("myRecord",false);
index++;
byte b[]=("Record NO "+index).getBytes();
//Adding record to record store
rs.addRecord(b,0,b.length);
rs.closeRecordStore() ;
} catch(Exception e) {
System.out.println(e);
}
}
// Deleting a record
void removeRecord(int recordID) {
try {
rs= RecordStore.openRecordStore("myRecord",false);
rs.deleteRecord(recordID);
index--;
rs.closeRecordStore();
} catch(Exception e) {
System.out.println(e);
}
}
}
how to apply it to an application. i mean how to capture information to b store from a form
ReplyDeleteHow to Connect a database with J2ME
ReplyDeletewhich database r u using. is it online or offline
DeleteAll programms coding wrong,y r u puuting coding in net
ReplyDeletewhere does the location of "my record" ?
ReplyDeleteim using record store in my progra when i delete something from my record i am not able to save the
ReplyDeleteplease provide some detail line above code for what that particular code id use.
ReplyDeletesimply purchase a Book and study it throughly... got it !!!
ReplyDeletei have developed a form whic has a textfield of username n date of birth can istor it in mobile ???is it possible please help me out in this part of problem
ReplyDeleteDoes exactly what it say's on the tin!
ReplyDeleteBasic RMS example - you need to build the fence, then paint it!
simply purchase a Book and study it throughly... got it
ReplyDeleteThats good!!!!!!!!!!!!!11
ReplyDeleteyou've gotta correct this code
ReplyDeleteC:\Documents and Settings\Administrator\j2mewtk\2.5.2\apps\RMSDemo\src\RMSDemo.java:57: '.class' expected
ReplyDeleteaddRecord(int);
^
1 error
com.sun.kvem.ktools.ExecutionException
Build failed
this code has a lot of errors, here is the corrected version:
ReplyDeleteimport javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
import java.io.*;
public class RMSDemo extends MIDlet implements CommandListener {
private Display display;
private RecordStore rs=null;
private Command exit,add,delete,show;
private RecordEnumeration re;
private int recordNO,recordID;
Form frm;
int index=0;
public RMSDemo() {
display = Display.getDisplay(this);
//Create a RMS
try {
rs= RecordStore.openRecordStore("myRecord",false);
rs.closeRecordStore();
} catch(Exception e) {
System.out.println(e);
}
}
public void startApp() {
frm=new Form("RMSDemo");
exit= new Command("Exit",Command.EXIT,1);
frm.addCommand(exit);
add= new Command("Add",Command.SCREEN,1);
frm.addCommand(add);
delete= new Command("Delete",Command.SCREEN,2);
frm.addCommand(delete);
show= new Command("SHOW",Command.SCREEN ,3);
frm.addCommand(show);
frm.setCommandListener(this);
frm.append("#####");
display.setCurrent(frm);
}
public void pauseApp() {
}
public void destroyApp(boolean un) {
}
// Handling commands
public void commandAction(Command cmd,Displayable d) {
if(cmd==add) {
addRecord();
} else
if(cmd==delete) {
removeRecord();
} else
if(cmd==show) {
try {
byte b[]= rs.getRecord(recordNO);
String s= new String(b);
frm.append(s);
} catch(Exception e) {}
}
}
void addRecord() {
try {
rs= RecordStore.openRecordStore("myRecord",false);
index++;
byte b[]=("Record NO "+index).getBytes();
//Adding record to record store
rs.addRecord(b,0,b.length);
rs.closeRecordStore() ;
} catch(Exception e) {
System.out.println(e);
}
}
// Deleting a record
public void removeRecord() {
try {
rs= RecordStore.openRecordStore("myRecord",false);
rs.deleteRecord(recordID);
index--;
rs.closeRecordStore();
} catch(Exception e) {
System.out.println(e);
}
}
}
how to retrieve datasets in j2me app from sql database server??
ReplyDeleteI made some minor changes to this example to get it working for my application. Here's the snips for getting a new RMS to load into your phone app:
ReplyDeleteThe integer parameter is for the record number that the addRecord would create:
public String ReadRMSSettings(int r)
{
try
{
rs = RecordStore.openRecordStore("METARsRMS", true);
// if there are no records in the RMS then lets ADD one
if(rs.getNumRecords() == 0)
{
// SETTING_DEFAULT_STATION
rs.addRecord(rsBytes, 0, rsBytes.length);
}
// now reading that record
ret = rs.getRecord(r, rsBytes, 0);
tempString = new String(rsBytes);
rs.closeRecordStore();
}
catch(Exception ex)
{
Error(ex.toString());
return "";
}
return tempString;
}
and some code to update the RMS record
public void UpdateRMSSettings(String s, int r)
{
try
{
rs = RecordStore.openRecordStore("METARsRMS", true);
rsBytes = s.getBytes();
rs.setRecord(r, rsBytes, 0, rsBytes.length);
rs.closeRecordStore();
}
catch(Exception ex)
{
Error(ex.toString());
}
}
calling the methods
public static final int SETTING_DEFAULT_STATION = 1;
tempString = ReadRMSSettings(SETTING_DEFAULT_STATION);
UpdateRMSSettings(station.getString(), SETTING_DEFAULT_STATION);
btw: when the RMS is empty and you add the first record to it its record number is one and with each add it adds one to the record number. So, if you wanted to save 10 settings loop the add 10 times and then have constants for each of the 10 records ie. SETTING_DEFAULT_STATION = 1.
Delete