java left logo
java middle logo
java right logo
 

Home arrow Java ME Tips
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4100
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
Record Management System for storing/retrieving data on mobile E-mail
User Rating: / 10
PoorBest 

Midlets can be programmed to store data at runtime with RMS mechanism. The package javax.microedition.rms is used to implement the functionality of RMS APIs. This package provides facilities for storing, getting, deleting and comparing data.

Some methods are written below to demonstrates some functionalities of RMS:

/* Open database */
public void startApp()
{

   try 
   {
      RecordStore recordStore = RecordStore.openRecordStore("file", true, 
        RecordStore.AUTHMODE_ANY,true);
   }
   catch(RecordStoreException rse)
   {
      rse.printStackTrace();
   }
}

/* Close database */
public void close() throws RecordStoreNotOpenException,RecordStoreException 
{
   String fileName = recordStore.getName();
   recordStore.closeRecordStore();
   recordStore.deleteRecordStore(fileName);
}

/* Enter data */
public void enterData()
{
   byte[] rec;
   String str = "hello";
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   DataOutputStream outputStream = new DataOutputStream(baos);

   try
   {
      outputStream.writeUTF(str);
      outputStream.flush();
      rec = baos.toByteArray();
      recordStore.addRecord(rec,0,rec.length);
      baos.reset();
      outputStream.close();
      outputStream = null;
      
   }
   catch (IOException e) {

      e.printStackTrace();
      outputStream =null;
   }
   catch(RecordStoreException e) {
      
      e.printStackTrace();
      outputStream =null;
   }
}

/* Enumerate data */
public synchronized RecordEnumeration enumerate() 
  throws RecordStoreNotOpenException
{
   return recordStore.enumerateRecords(null, null, false);
}

/* Get data */
public void getdata()
{
   RecordEnumeration recEnum;
   byte[] rec = null;
   String str = null;
   
   try {    

      recEnum = enumerate();
      
      while (recEnum.hasNextElement())
      {
         rec = recEnum.nextRecord();
         ByteArrayInputStream  bin =  new ByteArrayInputStreamrec);
         DataInputStream   din = new DataInputStreambin );
         str = din.readUTF();
      }
   }
   catch (Exception e) {}
}

/* Compare data */
public class dataComaparator implements RecordComaparator
{
   
   public int compare(byte[] rec1,byte[] rec2
   {
      int compVal;
      String rec1,rec2;
      String value;
      
      try {
  
        ByteArrayInputStream  bin =  new ByteArrayInputStreamrec1 );  
        DataInputStream   din = new DataInputStreambin );
        rec1 = din.readUTF();
  
        bin = new ByteArrayInputStreamrec2 );
        din = new DataInputStreambin );

        rec2 = din.readUTF();
        compVal= rec1.compareTo(rec2);

        bin.reset();
        din.close();
        din =null;
      }
      catch (IOException e)
      {
     e.printStackTrace();
      }
   }
}


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.