×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    12

    How to link records?

    Quote Originally Posted by grahamhughes View Post
    First thing to remember about RMS is: it is not a relational database. This might seem obvious, but if you are new to mobile (and I'm guessing you are), you really need to reduce your expectations.

    I recommend you read some threads on the forum about RMS. You might also find the wiki useful.

    Records are identified by record ID - an integer allocated to the record when it is created (the return value from addRecord()). By storing the ID of one record, in another record, you can effectively "link" this records. Think of the ID as like the "primary key".

    Graham.

    Graham,

    Thank you for the information.
    Could you enlighten me on this line: "By storing the ID of one record, in another record, you can effectively "link" this records"?

    Do you mean it will be something like a text hyperlinked from record1 to record2?
    If possible, could you provide me with some coding example/template on this, as I am currently working on a school project with J2ME.

  2. #2
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    88

    Re: How to link records?

    Hello,
    first of all, excuse to grahamhughes to anwser this question. As Grahm told, RMS stores an array of bytes and creates an id number when storing a new value. If you want to "link" two entities, let's say Vehicle and VehicleOwner, you can use the just created id of one to establish a relationship between them.

    Code:
    #Open record store Vehicle
    RecordStore record = RecordStore.openRecordStore(VEHICLE_RMS, true);
    
    ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
    DataOutputStream dataOut = new DataOutputStream(byteArray);
    dataOut.writeUTF("Ford");
    dataOut.flush();
    byte[] bytesVehicle = byteArray.toByteArray();
    #stores new vehicle
    int vehicleId = record.addRecord(bytesVehicle, 0, bytesVehicle.length);
    dataOut.close();
    byteArray.close();
    record.closeRecordStore();
    
    
    
    #Open record store Vehicle owner
    record = RecordStore.openRecordStore(VEHICLE_OWNER_RMS, true);
    ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
    DataOutputStream dataOut = new DataOutputStream(byteArray);
    dataOut.writeInt(vehicleId); #Links just stored vehicle to its "owner"
    dataOut.writeUTF("Thiagobrunoms"); #Owner's name
    dataOut.flush();
    
    byte[] bytesOnwer = byteArray.toByteArray();	
    
    #stores new owner
    int ownerId = record.addRecord(bytesOnwer, 0, bytesOnwer.length);
    
    dataOut.close();
    byteArray.close();
    record.closeRecordStore();
    []'s

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    12

    Re: How to link records?

    Thiagobrunoms,

    Thanks for the coding example. I will give that a try.

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

    Re: How to link records?

    Quote Originally Posted by thiagobrunoms View Post
    first of all, excuse to grahamhughes to anwser this question.
    Not at all. I hadn't spotted this thread (it's in reply to my post in another thead), so I appreciate you picking it up!

    Cheers,
    Graham.

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    12

    Re: How to link records?

    Hi,

    From what I understand from the suggested coding, it will output something like this:

    For Vehicle RMS,
    VehicleID: 1
    Vehicle: Ford

    For Vehicle Owner RMS,
    OwnerID: 5
    VehicleID: 1
    Vehicle Owner: Thiagobrunoms

    But is it achievable to create a "fake link" which allow selection of VehicleID=1 of Vehicle RMS (appear in screen 1)
    to "link" to VehicleID=1 of Vehicle Owner RMS (appear in screen 2)? What would happen if we have 20 over VehicleID?

    Look upon to your reply and advise. Thank you.

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

    Re: How to link records?

    An important question is: how much data are you likely to have?

    Also: is this an academic project, or commercial?

    Graham.

  7. #7
    Registered User
    Join Date
    Jul 2009
    Posts
    12

    Re: How to link records?

    Graham,

    My target is around 10 records. It is meant for a school-end project.
    Its main objective is to perform mapping of information.

    I hope you can advise me further because I am really stuck under this portion.

  8. #8
    Regular Contributor
    Join Date
    Feb 2010
    Posts
    69

    Re: How to link records?

    Hii

    just extending the experts view...

    as suggested in Vehicle RMS Structure u can have ur Student structure and use RecordFilter for searching records which have particular StudentID and display those resulted records. This has a slow execution effect if records are more than 100. But in your case where hav less number of records u can use RecordFilter.

    just havea look at this article http://www.ibm.com/developerworks/library/j-j2me3/

    hope this will help u.

    Nikesh~
    Enthusiastic

Similar Threads

  1. [newbie here] Link error
    By xitpu in forum Symbian
    Replies: 3
    Last Post: 2007-01-24, 16:53
  2. armi urel in codewarrior
    By arthig in forum Symbian
    Replies: 0
    Last Post: 2005-04-06, 10:13
  3. Linking Errors: Pls Help....
    By amanjha14 in forum Symbian
    Replies: 2
    Last Post: 2004-12-03, 09:03
  4. Link error
    By SimoneF85 in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2004-11-09, 18:07

Posting Permissions

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