This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java 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

Doubt in deletion of record in RMS  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,
I've got error while retrieving records from RMS, after deleting a record in it. The error message is that InvalidRecordID exception.
My doubt is, after deleting a record in RMS, how can we retrieve records. Say for example, an RMS contains five records. I just delete 3 record. Upto this everying goes fine. But while retrieving remaining records after deletion, now it shows only first two records. Remaining two records are not displayed and it shows the above error message.
I hereby included the source code for the deletion application. Kindly give your idea regarding the same.
Expecting for your response,
Chandru
------------------------------------------------
Here you have to give input as any data and store them by clicking menu command and select Add option in it. If you select Retrieve command it will show the records in RMS. To delete a record say 3, you just give input as 3 and select Delete option from Menu command. Now it will delete 3rd record successfully.
But, if you try to retrieve remaining records now only first two records will be displayed and while accessing third record you will be getting error.
Here is the code.
------------------------------------------------
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
public class RSDelete extends MIDlet implements CommandListener
{
private Command retrieveCommand;
private Command okCommand;
private Command deleteCommand;
private Display display;
private TextBox t = null;
String dbn=new String("Sample");
RecordStore rs=null;
int currpos,maxchar;
public RSDelete()
{
display = Display.getDisplay(this);
retrieveCommand = new Command("Retrieve", Command.OK, 2);
okCommand = new Command("Add", Command.OK, 2);
deleteCommand = new Command("Delete", Command.OK, 2);
t = new TextBox("Enter your data :", "",256, 0);
t.addCommand(retrieveCommand);
t.addCommand(okCommand);
t.addCommand(deleteCommand);
t.setCommandListener(this);
}
public void startApp()
{
display.setCurrent(t);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void commandAction(Command c, Displayable s)
{
try
{
if(c == okCommand)
{
rs=RecordStore.openRecordStore(dbn,true);
String name = "";
name=new String(t.getString());
byte[] data=name.getBytes();
rs.addRecord(data,0,name.length());
System.out.println(" Record is updated");
rs.closeRecordStore();
}
if(c == deleteCommand)
{
rs=RecordStore.openRecordStore(dbn,true);
int id = Integer.parseInt(t.getString());
int totalRecords = rs.getNumRecords();
boolean flag = false;
for(int i = 1; i <= totalRecords; i++)
{
if(i == id)
{
rs.deleteRecord(id);
flag = true;
break;
}
}
if(flag)
System.out.println("record :"+id+" is deleted ");
else
System.out.println("No match found");
rs.closeRecordStore();
} /* end of Add command */
if(c == retrieveCommand)
{
rs=RecordStore.openRecordStore(dbn,true);
String result = "";
byte[] data = null;
System.out.println("Rows in the rs are :");
System.out.println("records in rms :"+rs.getNumRecords());
int totalRecords = rs.getNumRecords();
for(int i = 1; i <= totalRecords; i++)
{
data = rs.getRecord(i);
result = new String(data);
System.out.println(i+": " + result);
}
rs.closeRecordStore();
}
}catch(RecordStoreException e)
{
System.out.println(" Error :"+e);
}
} /* end of command Action */
} /* end of class */
-----------------------------------------------------------


 
Seriously? That's what you're going with? I prefer this tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!