×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    158

    updating & deleted records in rms

    public void update_function(String add_name,String add_no,String blood,String delete_id)
    {
    try{
    recordstore=RecordStore.openRecordStore("bloodbank",false);
    byte outputrecord[]= recordstore.getRecord(Integer.parseInt(delete_id));
    ByteArrayOutputStream outputstream_bytearray=new ByteArrayOutputStream();
    DataOutputStream outputstream_data=new DataOutputStream(outputstream_bytearray);
    outputstream_data.writeUTF(blood);
    outputstream_data.writeUTF(add_name);
    outputstream_data.writeUTF(add_no);
    outputstream_data.flush();
    outputrecord=outputstream_bytearray.toByteArray();
    recordstore.setRecord(Integer.parseInt(delete_id), outputrecord, 0, outputrecord.length);
    outputstream_bytearray.close();
    outputstream_data.close();
    }
    catch(Exception e)
    {

    }
    finally
    {
    try{
    recordstore.closeRecordStore();


    }
    catch(Exception e)
    {

    }
    }
    }
    public void delete_function(String delete_id)
    {
    try{
    recordstore=RecordStore.openRecordStore("bloodbank",false);
    recordstore.deleteRecord(Integer.parseInt(delete_id));
    }
    catch(Exception e)
    {

    }
    finally
    {
    try{
    recordstore.closeRecordStore();


    }
    catch(Exception e)
    {

    }
    }
    }




    i have prob in updating and deleting.....no changes is seen.....

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

    Re: updating & deleted records in rms

    What device are you doing this on?

    I'd recommend you pass the ID around as an int, not a String.

    Also, you are silently ignoring any and all exceptions... if the runtime is trying to tell you what went wrong, you won't find out.

    Avoid using a non-local variable to hold the record store reference.

    Code like this is much easier to work with:

    Code:
    void deleteRecord(int id) throws RecordStoreException {
        RecordStore rs = RecordStore.openRecordStore(RECORD_STORE_NAME);
        try {
            rs.deleteRecord(id);
        } finally {
            rs.closeRecordStore();
        }
    }

  3. #3
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    158

    Re: updating & deleted records in rms

    im geeting id from text field...so it possible to do with string and den converting to int.....whats wrong with the above code

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

    Re: updating & deleted records in rms

    I don't have a magic power to tell you what's wrong. You need to give me some clues.

    What device are you using?

    Why is recordstore not local? I suggest you use local variables for this.

    Don't pass the String ID to this code. Validate the ID on input, and convert it to an int then.

  5. #5
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: updating & deleted records in rms

    Quote Originally Posted by jselvakumar26071988 View Post
    im geeting id from text field...so it possible to do with string and den converting to int.....whats wrong with the above code
    Hi,
    Well thats a problem, most of the time developers has to face...
    However its not too tuff that it cant be done...there are so many demo on google ..you can find the same..
    Have you read some tutorials on it..

    Updating a particular record involves getting a handle for that record and setting new information.

    public int getRecord(int recordId, byte[] buffer, int offset) returns the data stored in the given record in the byte array represented by buffer. public byte[] getRecord(int recorded) returns a copy of the data represented by recordId. public void setRecord(int recordId, byte[] newData, int offset, int numBytes) sets new information, a stream of bytes (newData) with offset as its starting index and numBytes as its length, at the record location represented by recordId.

    Listing 5. Update a record

    String newappt = "update record";
    Byte data = newappt.getBytes();
    Rs.setRecord(1, data, 0, data.length());


    Deleting records

    The MIDlet invokes the deleteRecord() method to delete a record from the record store.

    public void deleteRecord(int recordId) deletes the record represented by recordId. The recordId for this record is not subsequently reused.


    Rs.deleteRecord(1);

    Here are some link
    http://developers.sun.com/mobility/m...s/databaserms/
    Hope this helps you,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  6. #6
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    158

    Re: updating & deleted records in rms

    i tried.....its mixed data type....dunno how to delete and update....can anyone rectify my code........

  7. #7
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    158

    Re: updating & deleted records in rms

    both working...thanks guys
    Last edited by jselvakumar26071988; 2008-12-06 at 12:13.

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

    Re: updating & deleted records in rms

    I can't help you if you won't give me any more information.

  9. #9
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    158

    Re: updating & deleted records in rms

    now the prob again arises.....adding/deleting is not synchronised.....though after deletion if add new values i get the deleted values too...i know record enumeration is the prob.i tried keptupdated()...
    Last edited by jselvakumar26071988; 2008-12-14 at 20:46.

  10. #10
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    158

    Re: updating & deleted records in rms

    now the prob again arises.....adding/deleting is not synchronised.....though after deletion if add new values i get the deleted values too...i know record enumeration is the prob.i tried keptupdated()...

  11. #11
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: updating & deleted records in rms

    Hi,
    Well, can you share that what exactly you are looking for??
    Which functionalities you want o implement..like this no one can help you,
    Now nothing is clear that what is happening and what not..
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  12. #12
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    158

    Re: updating & deleted records in rms

    same rms searching complete reference code....but its i/p are dynamic.for eg
    1.selva
    operation:deleted record(1);
    o/p:no record


    operation:added surya
    o/p:1.selva
    2.surya

    i have used recordenmeration...i think ,it doesn't rebuild its internal id.

  13. #13
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    158

    Re: updating & deleted records in rms

    In reference to "j2me complete reference:rms mixed datatype"
    writeutf is used for strings.

    now the prob is,if i have two strings(dynamic) whether i have to use writeutf & readutf two times ?

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

    Re: updating & deleted records in rms

    Yes you do.

  15. #15
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: updating & deleted records in rms

    Hi,
    You have the two string variables ..to write in RMS...These must be having some values...

    Just use simple method of the data writing--

    -------------------- Writing -------------------------
    @ open the RMS
    @ have the string..
    @ convert the same in bytes ..
    @ add the bytes in RMS using addRecord().

    try
    {
    recordstore = RecordStore.openRecordStore(
    "myRecordStore", true );
    }
    catch (Exception error)
    {
    alert = new Alert("Error Creating",
    error.toString(), null, AlertType.WARNING);
    alert.setTimeout(Alert.FOREVER);
    display.setCurrent(alert);
    }
    try
    {
    String outputData = "First Record";
    byte[] byteOutputData = outputData.getBytes();
    recordstore.addRecord(byteOutputData, 0,
    byteOutputData.length);
    }
    catch ( Exception error)
    {
    alert = new Alert("Error Writing",
    error.toString(), null, AlertType.WARNING);
    alert.setTimeout(Alert.FOREVER);
    display.setCurrent(alert);

    ------------------------- Reading -----------------------------
    try
    {
    byte[] byteInputData = new byte[1];
    int length = 0;
    for (int x = 1; x <= recordstore.getNumRecords(); x++)
    {
    if (recordstore.getRecordSize(x) > byteInputData.length)
    {
    byteInputData = new byte[recordstore.getRecordSize(x)];
    }
    length = recordstore.getRecord(x, byteInputData, 0);
    }
    alert = new Alert("Reading", new String(byteInputData, 0,
    length), null, AlertType.WARNING);
    alert.setTimeout(Alert.FOREVER);
    display.setCurrent(alert);


    }
    catch (Exception error)
    {
    alert = new Alert("Error Reading", error.toString(),
    null, AlertType.WARNING);
    alert.setTimeout(Alert.FOREVER);
    display.setCurrent(alert);
    }
    try
    {
    recordstore.closeRecordStore();
    }
    catch (Exception error)
    {
    alert = new Alert("Error Closing", error.toString(),
    null, AlertType.WARNING);
    alert.setTimeout(Alert.FOREVER);
    display.setCurrent(alert);
    }
    if (RecordStore.listRecordStores() != null)
    {
    try
    {
    RecordStore.deleteRecordStore("myRecordStore");
    }
    catch (Exception error)
    {
    alert = new Alert("Error Removing", error.toString(),
    null, AlertType.WARNING);
    alert.setTimeout(Alert.FOREVER);
    display.setCurrent(alert);
    }
    }
    }
    Hope that these liens can help you,
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. RMS record sizes.
    By earamsey in forum Mobile Java General
    Replies: 1
    Last Post: 2007-10-18, 13:51
  2. RMS questions -- updating and deleting records
    By earamsey in forum Mobile Java General
    Replies: 1
    Last Post: 2007-09-18, 18:16
  3. Replies: 3
    Last Post: 2007-03-23, 08:37
  4. RMS limits - max records per recordstore
    By conos in forum Mobile Java General
    Replies: 3
    Last Post: 2007-02-28, 10:15
  5. updating RMS records
    By newmania in forum Mobile Java General
    Replies: 0
    Last Post: 2003-04-14, 17:47

Posting Permissions

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