×

Discussion Board

Results 1 to 9 of 9

Thread: database help

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

    database help

    hi everyone.i have created a mobile database using rms.i know its resource is limited..i read from the tutorials that it saves database as a file..
    1.is it possible to see the file?
    2.wat the max size?
    3.is it possible to move the file to my memory card..so that i can store large no of records?
    4.is there any other technology avail in j2me to store the records?
    my cell is nokia 3230
    Edit/Delete Message
    Reply With Quote

  2. #2
    Regular Contributor
    Join Date
    Jun 2008
    Location
    Singapore
    Posts
    167

    Re: database help

    Hi,

    Basicly the RMS records embeded inside your jar package. You have to acess to RMS through your application, that is depends on how you write data, it should be read accordingly.

    If you install jar with option to your memory card, the rms therefore should be stored in rms also. There is specification of rms limitation size. It should be depends on device memory avaliable (varies from device to device).

    Hope this helps.
    ---Knowledge sharing is power---

    Hans

  3. #3
    Registered User
    Join Date
    Jul 2008
    Location
    Banglore INDIA
    Posts
    34

    Exclamation Re: database help

    Hi selvakumar,

    I am new to j2me.I am learning RMS.So is it possible for you to send me the related code ,so that i could study and understand the RMS to some extent.My Mail id is : cutenik73@gmail.com.

    Regards
    Shashi

  4. #4
    Regular Contributor
    Join Date
    Apr 2007
    Posts
    220

    Re: database help

    Hi,

    I think the following link will be helpful to you-

    http://www.java2s.com/Code/Java/J2ME...ecordstore.htm

    Regards
    Amit

  5. #5
    Regular Contributor
    Join Date
    Jun 2008
    Location
    Singapore
    Posts
    167

    Re: database help

    Hi,

    The article from sun should be very good for you.

    http://developers.sun.com/mobility/a...les/#databases

    Plus, check API from:
    http://java.sun.com/javame/reference/apis/jsr118/


    The coding of mine or anyone should be more or less the same from the SUN article.
    ---Knowledge sharing is power---

    Hans

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

    Re: database help

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.rms.RecordStoreException;
    public class RecordMIDlet
    extends MIDlet
    implements CommandListener {
    private static final String kUser = "user";
    private static final String kPassword = "password";
    private Preferences mPreferences;
    private Form mForm;
    private TextField mUserField, mPasswordField;
    public RecordMIDlet() {
    try {
    mPreferences = new Preferences("preferences");
    }
    catch (RecordStoreException rse) {
    mForm = new Form("Exception");
    mForm.append(new StringItem(null, rse.toString()));
    mForm.addCommand(new Command("Exit", Command.EXIT, 0));
    mForm.setCommandListener(this);
    return;
    }
    mForm = new Form("Login");
    mUserField = new TextField("Name",
    mPreferences.get(kUser), 32, 0);
    mPasswordField = new TextField("Password",
    mPreferences.get(kPassword), 32, 0);
    mForm.append(mUserField);
    mForm.append(mPasswordField);
    mForm.addCommand(new Command("Exit", Command.EXIT, 0));
    mForm.setCommandListener(this);
    }
    public void startApp() {
    Display.getDisplay(this).setCurrent(mForm);
    }
    public void pauseApp() {}
    public void destroyApp(boolean unconditional) {
    // Save the user name and password.
    mPreferences.put(kUser, mUserField.getString());
    mPreferences.put(kPassword, mPasswordField.getString());
    try { mPreferences.save(); }
    catch (RecordStoreException rse) {}
    }
    public void commandAction(Command c, Displayable s) {
    if (c.getCommandType() == Command.EXIT) {
    destroyApp(true);
    notifyDestroyed();
    }
    }
    }








    import java.util.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.rms.*;
    public class Preferences {
    private String mRecordStoreName;
    private Hashtable mHashtable;
    public Preferences(String recordStoreName)
    throws RecordStoreException {
    mRecordStoreName = recordStoreName;
    mHashtable = new Hashtable();
    load();
    }
    public String get(String key) {
    return (String)mHashtable.get(key);
    }
    public void put(String key, String value) {
    if (value == null) value = "";
    mHashtable.put(key, value);
    }
    private void load() throws RecordStoreException {
    RecordStore rs = null;
    RecordEnumeration re = null;
    try {
    rs = RecordStore.openRecordStore(mRecordStoreName, true);
    re = rs.enumerateRecords(null, null, false);
    while (re.hasNextElement()) {
    byte[] raw = re.nextRecord();
    String pref = new String(raw);
    // Parse out the name.
    int index = pref.indexOf('|');
    String name = pref.substring(0, index);
    String value = pref.substring(index + 1);
    put(name, value);
    }
    }
    finally {
    if (re != null) re.destroy();
    if (rs != null) rs.closeRecordStore();
    }
    }
    public void save() throws RecordStoreException {
    RecordStore rs = null;
    RecordEnumeration re = null;
    try {
    rs = RecordStore.openRecordStore(mRecordStoreName, true);
    re = rs.enumerateRecords(null, null, false);
    // First remove all records, a little clumsy.
    while (re.hasNextElement()) {
    int id = re.nextRecordId();
    rs.deleteRecord(id);
    }

    Enumeration keys = mHashtable.keys();
    while (keys.hasMoreElements()) {
    String key = (String)keys.nextElement();
    String value = get(key);
    String pref = key + "|" + value;
    byte[] raw = pref.getBytes();
    rs.addRecord(raw, 0, raw.length);
    }
    }
    finally {
    if (re != null) re.destroy();
    if (rs != null) rs.closeRecordStore();
    }
    }
    }

  7. #7
    Regular Contributor
    Join Date
    Jul 2003
    Posts
    89

    Re: database help

    Sashi

    Have a look at Forum Nokia JavaME Developers Library. It has all the information to help you get started.

    http://www.forum.nokia.com/main/reso...rs_library.htm

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

    Re: database help

    thanks guys...dats great......
    final question..i have to store name and phone no.
    is it possible to store 1000 records....or else wat is de max?

  9. #9
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: database help

    If you mean the maximum size of the record store, this article explains it.

Similar Threads

  1. Application Closed! KERN-EXEC 0
    By smnsolomon in forum Symbian
    Replies: 3
    Last Post: 2008-04-20, 15:36
  2. Replies: 2
    Last Post: 2008-02-28, 10:13
  3. database trouble
    By liafail in forum Symbian
    Replies: 6
    Last Post: 2005-12-28, 05:56
  4. InsertL in database Controls the DB
    By Blkangel in forum Symbian
    Replies: 5
    Last Post: 2004-01-13, 15:02
  5. database problem
    By sridhar_ratna in forum Symbian
    Replies: 1
    Last Post: 2003-04-18, 09: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
  •