Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Oct 2009

    Red face Read record in rms

    Hi all...

    i must read a single record in a RecordStore...

    but when i read it, i see a byte format...

    i have try to use toString() functions, but there is an error...

    Post my code...

    try {
                // Inserimento
                z = recordStore.getRecord(1);
            catch(Exception e){
            System.out.println("z "+z);
            String z1,z2;
            z2="prova"; //controllo della stringa nulla!!!!
            System.out.println("z1 "+z1);
            System.out.println("z2 "+z2);
                byte[] record= test.getBytes();
                try {
                    recordStore.setRecord(1, record,0, record.length);
                    System.out.println("Inserimento effettuato di prova");
                    System.out.println("Dato inserito " + test + " indice sul record ");// + id);
                } catch (Exception e) {
            }// inserimento prova
                      byte[] w =recordStore.getRecord(1);
                catch(Exception e){
                System.out.println("Digitato " + dato);
                System.out.println("test" +test);
                    System.out.println("Password accettata");
                    //Controllare l'if
                else if (test.compareTo(dato)>0){
                    System.out.println("Password errata");
                    System.out.println("Password errata");

    Where is my error???


  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Cheshire, UK

    Re: Read record in rms

    Quote Originally Posted by slackware15 View Post
    i have try to use toString() functions, but there is an error...
    It's always a lot more help if you tell us what the error is. More detail = more help.

    RecordStores store byte[]s. They don't store anything else. Anything else must be converted to a byte[] and back.

    byte[].toString() does not give you the what you want. It will give you a result like "[B@3e25a5", as specified by Object.toString() (which arrays inherit). Use the String constructor to create a new String from a byte[].

    Be careful with these methods:

    // AVOID!
    byte[] b = "pizza".getBytes();
    String s = new String(b);
    Remember that characters in Java are 16 bit. Converting 16 bit data to an 8 bit format requires an encoding system. These two methods use the platform default encoding. This results in two problems.

    1. Different devices use different encoding systems by default. This means that the same code will behave differently on different devices.

    2. Not all encoding systems are unicode-safe. If the encoding system used is not unicode-safe, then you might not get back the original string you started with. Some characters might get lost or altered.

    Instead, specify the encoding. The safest encoding to use is UTF-8.

    // better!
    byte[] b = "pizza".getBytes("UTF-8");
    String s = new String(b, "UTF-8");
    Alternatively, if you want to store more complex data in RMS, use a DataOutputStream and a ByteArrayOutputStream to create a byte array from a sequence of data values. The corresponding Input classes can be used to retrieve the items from the byte array in the same order.


  3. #3
    Registered User
    Join Date
    Oct 2009

    Re: Read record in rms

    Hey Slackware15,

    If you like to avoid the String encoding problem all the RMS verbosely try Floggy (www.floggy.org).


Similar Threads

  1. RMS Design and Implementation hints
    By ahmedsharaf2006 in forum Mobile Java General
    Replies: 1
    Last Post: 2011-10-22, 20:21
  2. RMS record search and to place in an array
    By udaykapavarapu in forum Mobile Java General
    Replies: 4
    Last Post: 2009-04-08, 07:23
  3. interesting problem with RMS ... have a look..
    By amishra in forum Mobile Java General
    Replies: 4
    Last Post: 2008-08-14, 11:42
  4. Record comparison in RMS...
    By snehalpatil in forum Mobile Java General
    Replies: 2
    Last Post: 2008-02-19, 14:44
  5. Record Store Management System (RMS)
    By mister318 in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2004-03-23, 16:38

Posting Permissions

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