×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Regular Contributor
    Join Date
    Nov 2008
    Posts
    113

    Red face Store string in Record Store

    Hi All
    I want to store string in record store and retrieve them again .. I tried to do that many times but the code not work
    Can any one help me??
    thanks in advance

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

    Re: Store string in Record Store

    ITs So simple Convert String in to byte .....then store it in Record Store and get them in byte array and Again covert it into string


    String str;

    recordStore.addRecord(str.getBytes(), 0,str.getBytes().length);

    and u can get this by this methode

    String string = new String(record.getRecord(0));
    Anshu Chauhan
    J2me Developer

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

    Thumbs up Re: Store string in Record Store

    Hi,
    Follow suggested by ansh...for the task you have to do..
    for more operation/information check this link out..

    http://www.ibm.com/developerworks/li...e-j2me3-2.html
    and
    http://www.ibm.com/developerworks/library/j-j2me3/
    And a very good example -
    http://java.sun.com/developer/J2METe...02/tt0226.html
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  4. #4
    Regular Contributor
    Join Date
    Nov 2008
    Posts
    113

    Re: Store string in Record Store

    Raj and Ansh
    really thanks for quick reply

  5. #5
    Regular Contributor
    Join Date
    Nov 2008
    Posts
    113

    Re: Store string in Record Store

    (
    I wrote this code right now but not working
    I don't know where is the problem

    I have a list containing some of string elements
    I tried to save these elements one by one by select it from the list and select save command
    so I wrote this code inside save command

    String __selectedString = getDevicesList().getString(getDevicesList().getSelectedIndex());

    try {
    openRecStore();
    } catch (RecordStoreException ex) {
    ex.printStackTrace();
    }
    writeStream(__selectedString);
    writeStream and openRecStore() methods as follow

    public void openRecStore() throws RecordStoreException
    {
    // Create record store if it does not exist
    rs = RecordStore.openRecordStore(REC_STORE, true);
    }

    public void writeStream( String sData)
    {
    try
    {
    // Write data into an internal byte array
    ByteArrayOutputStream strmBytes = new ByteArrayOutputStream();

    // Write Java data types into the above byte array
    DataOutputStream strmDataType = new DataOutputStream(strmBytes);
    byte[] record;

    strmDataType.writeUTF(sData);

    // Clear any buffered data
    strmDataType.flush();

    // Get stream data into byte array and write record
    record = strmBytes.toByteArray();
    rs.addRecord(record, 0, record.length);

    // Toss any data in the internal array so writes
    // starts at beginning (of the internal array)
    strmBytes.reset();


    strmBytes.close();
    strmDataType.close();

    }
    catch (Exception e)
    {

    }
    }
    and then browse the database , retrieve element from record store by following code

    public String readStream()
    { String rdevice="";
    try
    {
    // Allocate space to hold each record
    byte[] recData = new byte[50];

    // Read from the specified byte array
    ByteArrayInputStream strmBytes = new ByteArrayInputStream(recData);

    // Read Java data types from the above byte array
    DataInputStream strmDataType = new DataInputStream(strmBytes);

    for (int i = 1; i <= rs.getNumRecords(); i++)
    {
    // Get data into the byte array
    rs.getRecord(i, recData, 0);


    // Reset so read starts at beginning of array
    rdevice=strmDataType.readUTF();
    strmBytes.reset();
    }

    strmBytes.close();
    strmDataType.close();

    }
    catch (Exception e)
    {
    e.printStackTrace();
    }
    return rdevice;
    }
    appending that returned string to browse list..
    when I select save the app hanging up and does not switch to alarm that supposed to switch to.
    what is the problem ??? can any one help me plz ?

  6. #6
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: Store string in Record Store

    Hi ,
    The writing of data looks fine . But retriving from the RMS you are using the for loop assuming that the record name will starts with 1 . It will be better if you use the RecordStoreEnumeration to loop through the record store.

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

    Re: Store string in Record Store

    U can USe this
    for (int i = 1; i <= rs.getNumRecords(); i++)
    {
    recData[i]=rs.getRecord(i+1);
    }
    Anshu Chauhan
    J2me Developer

  8. #8
    Regular Contributor
    Join Date
    Nov 2008
    Posts
    113

    Re: Store string in Record Store

    Hi All...
    I'm already store the data but the problem is when I close the application the stored data deleted ...
    I don't know where is the problem (
    the record store is permanent storage, isn't it???
    please I need help
    thanks in advance

  9. #9
    Nokia Developer Champion
    Join Date
    Sep 2007
    Posts
    915

    Re: Store string in Record Store

    Quote Originally Posted by Nourayn View Post
    Hi All...
    I'm already store the data but the problem is when I close the application the stored data deleted ...
    I don't know where is the problem (
    the record store is permanent storage, isn't it???
    please I need help
    thanks in advance
    It seems there should be some exception. ARe you watching what is going in catch block ? FIrst be confirm that there is not any exception. Are you using wireless toolkit or something else ?

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

    Thumbs up Re: Store string in Record Store

    Hi,
    Are calling some where RecordStroe method's called as deleteRecordStore()..like in code
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  11. #11
    Regular Contributor
    Join Date
    Nov 2008
    Posts
    113

    Re: Store string in Record Store

    honest and Raj really thanks for quick reply

    I'm using netbeans mobility package emulator, it does not support bluetooth so i can't know if exception thrown or not,


    Quote Originally Posted by raj_J2ME View Post
    Hi,
    Are calling some where RecordStroe method's called as deleteRecordStore()..like in code
    Thanks,
    No I don't call deleteRecordStore() any where of the code
    I just close the record store after reading stored data by calling rs.closeRecordStore()

    so.. what? 8(

  12. #12
    Registered User
    Join Date
    Nov 2008
    Posts
    2

    Re: Store string in Record Store

    There might be some exception. You sould be certain that there is not any exception. Are you using wireless toolkit or something else?

    _______________________________________
    admin of discussion board "junk file removers"

  13. #13
    Regular Contributor
    Join Date
    Nov 2008
    Posts
    113

    Re: Store string in Record Store

    Quote Originally Posted by winkygizer View Post
    There might be some exception. You sould be certain that there is not any exception. Are you using wireless toolkit or something else?

    _______________________________________
    admin of discussion board "junk file removers"

    I said that I'm using netbeans mobility package emulator, it does not support bluetooth so i can't know if exception thrown or not,
    so how can I know if there is thrown exception???
    plz help

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

    Re: Store string in Record Store

    IF u tested ur application is on netbean then u wil get this problem i m sure becoz netbeans create temporary Rms .Text it on Create ur project on sun WTk and then test it
    Anshu Chauhan
    J2me Developer

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

    Thumbs up Re: Store string in Record Store

    Hi,
    Can you find the path of the RMS file...
    Then just open this and check that the data you have just saved is present there or not..

    Is this also happening on device too..just check..it should not be happen..
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. Record Management Store issue
    By kartikm0021 in forum Mobile Java General
    Replies: 7
    Last Post: 2008-06-10, 16:41
  2. Register application: record store alternate
    By tgkprog@gmail.com in forum Mobile Java General
    Replies: 1
    Last Post: 2007-09-07, 08:21
  3. Record Store vs JDBC. How to store data?
    By 180ºrevolution in forum Mobile Java General
    Replies: 0
    Last Post: 2004-09-17, 15:24
  4. Record Store problem
    By anandmanish in forum Mobile Java General
    Replies: 3
    Last Post: 2003-09-15, 10:30
  5. Using protocol file:// with object connector
    By afinistr in forum Mobile Java General
    Replies: 2
    Last Post: 2002-06-24, 07:12

Posting Permissions

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