This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Please help me with a sample code.  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[code]
Hi...
I am new to j2me, I am trying to do a program such that I need to open a record store and save some data. And when I close the midlet and open it for the second time I need to view the data. I have written a small piece of code. But what happens in my code is each time when I close the midlet and open it again the previous saved data is not seen.

My Code..
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package pack;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;


public class Rms extends MIDlet {
private Form f;
public RecordStore rs;
Command c;
public void startApp() {
try{

rs=RecordStore.openRecordStore("dd", true);

byte [] dateBytes = "Shafeer".getBytes();
int dataBytesLength = dateBytes.length;
byte [] textBytes = "Taj Manzil".getBytes();
int textBytesLength = textBytes.length;
byte [] data = new byte [dataBytesLength + textBytesLength];
int i;
for (i = 0; i < dataBytesLength; i++)
data[i] = dateBytes[i];
for (i = 0; i < textBytesLength; i++)
data[dataBytesLength + i] = textBytes[i];
//rs.setRecord(1,data,0,6);

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

f=new Form("sha");
StringBuffer sb=new StringBuffer();
String d=null;
int len;
byte [] result=null;

//for (int j = 1; j <= rs.getNumRecords(); j++)
// {
// if ((result = rs.getRecord(j)) != null) {
// sb.append(rs.getRecord(j));
// sb.append(""+j);
//result=rs.getRecord(j);
//len=rs.getRecord(j, data, 0);
//}
//}
result=rs.getRecord(0);
sb.append(""+new String(result));
for(int m=0;m<=result.length;m++)
{

}

//byte[] byteInputData=new byte[1];
//d= new String(byteInputData, 0,len);
c=new Command("Cancel",Command.BACK,2);
f.addCommand(c);
f.append(sb.toString());
Display g=Display.getDisplay(this);
g.setCurrent(f);
rs.closeRecordStore();
}
catch (RecordStoreException e) {
}


}
public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
try {
rs.closeRecordStore();
} catch (RecordStoreNotOpenException ex) {
ex.printStackTrace();
} catch (RecordStoreException ex) {
ex.printStackTrace();
}
}
}


In this code:
First time when I open the midlet it will display: Shafeer Taj Manzil
But when I close and open it again the String is displayed only once instead of
Shafeer Taj Manzil Shafeer Taj Manzil
it is showing only
Shafeer Taj Manzil

please help me out with a sample code..
[code]
 
Bartender
Posts: 20099
101
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Shafeer!

We don't have many rules here at the JavaRanch, but we do insist that you use you Real Name and not some sort of "handle" or obvious alias. If you're not sure about this, see
http://www.javaranch.com/name.jsp .
 
All of the following truths are shameless lies. But what about this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!