×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    28

    Question problem while deleting a record (i'm new 2 j2me)

    hi,

    i've an application which stores sms in its inbox..actually it does add the record properly but i'm not able to delete a record ..actually i'm NOT UNDERSTANDING hw 2 get the record id for any specific record TO DELETE IT ..is there any specific method to get the record id for a particular record ??
    and is there any particular process to be followed while deleting a record ..

    hope i get a reply soon

    reagrds,
    dino

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: problem while deleting a record (i'm new 2 j2me)

    What problem do you get when deleting?

    You cannot control record IDs. First record you add is "1". Second is "2" and so on. If you delete a record, that ID disappears, and will not be used again. So, if you delete record ID "3", your records will be 1, 2, 4, 5 (no more "3"). Next you add will be "6" (it will not use "3" again).

    When working with RecordStores, avoid keeping the recordstore open. Open it, use it, close it.

    PHP Code:
    public void doRecordStoreWork() throws RecordStoreException 
        
    RecordStore rs RecordStore.openRecordStore(RECORD_STORE_NAMEtrue); 
        try { 
            
    // add, update or delete records 
        
    finally 
            
    rs.closeRecordStore(); 
        } 

    The close() is in a finally{}, so that the record store is closed no matter what happens. If you do not close the record store properly, you may lose data.

    getNumRecords() tells you the number of records in the store. getNextRecordID() tells you the ID that will be given to the next record you add. These methods can return completely different values. When you delete a record, NumRecords goes down by one. NextRecordID does not change.

    You can see if a record ID is valid, by calling getRecord(), and catching the InvalidRecordIDException. This is a clumsy technique, but it is reliable.

    You can also use the enumerateRecords() method, to scan through records without having to know the IDs.

    However:

    I recommend against updating and deleting records in recordstores. Some devices can corrupt the recordstore if there are may set/add/delete Record()s.

    One technique is to read all the data, delete the recordstore, and create it again with the correct data.

    Cheers,
    Graham.

  3. #3
    Regular Contributor
    Join Date
    Jul 2008
    Location
    Faridabad(Delhi NCR)
    Posts
    343

    Re: problem while deleting a record (i'm new 2 j2me)

    Hey buddy If u directly delete record from Rms ..it wil always give problem...i did too much R&D on Rms...So Best Way Is that...firstly Open record Store
    and get All Data From Record Store and put it in ...Some VEctor...and delete ur database

    Then Delete the record which u wana delete from vector....
    and then Create New RecordStore with same name u created before and put all the vector data in ur recordstore
    this is the best example for deleting database..............

    Hope this wil work......
    Anshu Chauhan
    J2me Developer

  4. #4
    Nokia Developer Champion
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: problem while deleting a record (i'm new 2 j2me)

    hi dino,
    please check the following thread..

    http://discussion.forum.nokia.com/fo...d.php?t=160112

    there is lots of discussion regarding deletion of record from RMS..and still continues.

    thanks,
    jitu_goldie..
    thanks,
    jitu_goldie..

    KEEP TRYING..

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    28

    Re: problem while deleting a record (i'm new 2 j2me)

    hey guys ,

    thnx for replying ..i'll try them out ...

    regards,
    dino

  6. #6
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: problem while deleting a record (i'm new 2 j2me)

    Hello good day !!
    can i ask something about on how to delete records in j2me within a week i need to have automated deletion for my program example today is december 3,2012 the i have my record 50 records in my record store then tomorrow is december 4,2012 it is possible to delete old records all records in december 3 2012 automatically and all the records in december 4 ,2012 will remain. how can i do that

    Please help me thanks in regard..
    asap..

    God Bless !!!

  7. #7
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: problem while deleting a record (i'm new 2 j2me)

    You need to create your record structure in such a way, that you can easily parse the date out of the record - then - Open the RecordStore, Read all records 1-by-1, Parse and Check if the date is 3 dec - store the records id in a vector called to_delete. Once you pass thu all the records... then delete all record ids stored in to_delete vector.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  8. #8
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: problem while deleting a record (i'm new 2 j2me)

    this is my code

    try {
    re = addrBook.enumerateRecords(null, null, true);
    } catch (RecordStoreNotOpenException ex) {
    ex.printStackTrace();
    }

    int rid=0;


    try {
    while (re.hasNextElement()) {
    rid=re.nextRecordId();
    try {
    addrBook.deleteRecord(rid);
    } catch (RecordStoreNotOpenException ex) {
    ex.printStackTrace();
    } catch (InvalidRecordIDException ex) {
    ex.printStackTrace();
    } catch (RecordStoreException ex) {
    ex.printStackTrace();
    }
    }
    } catch (InvalidRecordIDException ex) {
    ex.printStackTrace();

    }



    it seems like when i save the record from textfield it will show to a list menu
    theres a mainscreen that will list all the data that save in registration ..


    then when i open a menu list i can see the data that i saved but i
    i want to have automatically deletion after 1 week all old records will delete
    and the new one for the day will remain..


    can you please give me some idea or code

    thanksss

  9. #9
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,566

    Re: problem while deleting a record (i'm new 2 j2me)

    If you want to delete records by date, you simply have to extend the records to store a date field too. Then you can provide a RecordFilter picking the 1+ week old entries only.

  10. #10
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: problem while deleting a record (i'm new 2 j2me)

    i have my date in my recordstore then i want to delete it by date.. can you please give me some codes i need it tomorrow morning thanks,,,
    i want to delete it automatically..

    thanks in regard..

  11. #11
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,566

    Re: problem while deleting a record (i'm new 2 j2me)

    How do you assemble and store the record?

  12. #12
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: problem while deleting a record (i'm new 2 j2me)

    i store data using recordstore.
    and this is my code


    this is one of the example of data in my recordstore


    Date Savedecember 3,2012
    Lastname:Takashi
    Firstname:Limbell
    Nickname:Bell
    Birthday:1987/12/01
    Address:Tokyo,Japan

    This is my code:

    try {
    re = addrBook.enumerateRecords(null, null, true);
    } catch (RecordStoreNotOpenException ex) {
    ex.printStackTrace();
    }

    int rid=0;


    try {
    while (re.hasNextElement()) {
    rid=re.nextRecordId();
    try {
    addrBook.deleteRecord(rid);
    } catch (RecordStoreNotOpenException ex) {
    ex.printStackTrace();
    } catch (InvalidRecordIDException ex) {
    ex.printStackTrace();
    } catch (RecordStoreException ex) {
    ex.printStackTrace();
    }
    }
    } catch (InvalidRecordIDException ex) {
    ex.printStackTrace();

    }


    something like that all i want is to save record and to automatic deleted
    but when i save the record and open my saving data ive seen it
    but when i existed and open it again it fading away ...

    can you please help me to save the record then it will automatically deleted when for the first week..

    Thanks in regard..
    God Bless !!

  13. #13
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,566

    Re: problem while deleting a record (i'm new 2 j2me)

    The funny thing is that date-based selection is exactly the example which the Java documentation uses. http://www.developer.nokia.com/Resou...ordFilter.html mentions a hypothetical "DateRecordFilter" class, however if you search for it with Google, you will find actual example implementations:
    Code:
    import java.io.*;
    import javax.microedition.rms.*;
    
    public class DateRecordFilter implements RecordFilter {
      long criterionDate;
    
      DateRecordFilter(long criterionDate) {this.criterionDate = criterionDate;}
    
      public boolean matches(byte[] candidate) {
        try {
          DataInputStream din = new DataInputStream(new ByteArrayInputStream(candidate));
          din.reset();
          if (din.readLong() >=criterionDate) return true;
        } catch (Exception e) {}
        return false;
      }
    }
    (picked from http://www.codeforge.com/read/74567/...ter.java__html)
    This code snippet assumes that your record starts with with the date field, stored as a 8-byte long, exactly what Date.getTime provides. Of course you will have to calculate how many milliseconds are there in a week (168*3600*1000 or so), and subtract it from "now" when creating the filter.
    And you will need to revert the comparison to "<".

  14. #14
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: problem while deleting a record (i'm new 2 j2me)

    Hello sir good day ..
    im a java programmer
    im using j2me..


    this is my new problem

    i have my registration form

    EXAMPLE

    REGISTRATION

    Name:
    Age:
    Address:
    Birthday:

    Then when i inserted data

    Name:James
    Age:25
    Address:Tokyo,Japan
    Birthday:March,30,1987


    then theres a command SAVE..
    when you press the command save the data that you have inserted will go to another form
    and the form name is "DATA"

    DATA FORM
    Name:James
    Age:25
    Address:Tokyo,Japan
    Birthday:March,30,1987

    Name:Micaela
    Age:34
    Address:Tokyo,Japan
    Birthday:April 12,1978


    Then theres a automatic deletion
    and its like i want to set that the Data maximum of 10 records only how can i do that
    and the 11th record will automatically delete?

    is that possible how can i do that.Thanks in regard

    Godbless More Power.

  15. #15
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: problem while deleting a record (i'm new 2 j2me)

    and its like i want to set that the Data maximum of 10 records only how can i do that
    and the 11th record will automatically delete?
    When 11th record is added, do you want to delete the 1st one or you want to stop addition of records after 10 are added...?
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

Page 1 of 2 12 LastLast

Similar Threads

  1. problem in a j2me program on Nokia 6630/6680
    By lappard in forum Mobile Java General
    Replies: 1
    Last Post: 2006-06-29, 01:43
  2. Obfuscator problem for J2ME polish
    By rudyanto in forum Mobile Java General
    Replies: 0
    Last Post: 2006-05-29, 14:06
  3. Replies: 2
    Last Post: 2006-05-02, 07:19
  4. J2ME HTTP Post problem
    By gilfr in forum Mobile Java General
    Replies: 2
    Last Post: 2003-06-11, 08:13
  5. OTA deploy problem from applications with record stores
    By mpadberg in forum Mobile Java General
    Replies: 0
    Last Post: 2002-12-10, 13:40

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •