J2ME SQL Query : HOW

Posted on 2007-10-10
Last Modified: 2013-11-24
J2ME Filter Class

Hi, i am a J2SE familiar with web development. I normally will use SQL Statement to query my database.

Now with J2ME's RMS system, i am stuck and lost on querying database.

This is my database structure in RMS.


 So, i wish to select certain record base on the condition something like this
SELECT * From [table_name] where Year ='XXX' and Month='YYY'

I have able to retrieve the entire record in RMS with this code:
            recordstore = RecordStore.openRecordStore("database_name", true);
            byte[] byteInputData = new byte[500];
            ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData);
            DataInputStream inputDataStream = new DataInputStream(inputStream);

            for (int x = 1; x <= recordstore.getNumRecords(); x++) {
                recordstore.getRecord(x, byteInputData, 0);
                input_id = inputDataStream.readInt();
                input_year = inputDataStream.readUTF();
                input_month = inputDataStream.readUTF();
                input_type = inputDataStream.readUTF();

I have also read the J2ME Filter in here
and i notice it's only able to search a single phrase or column only. So, not able to match what i want.

Thus, this is my question.

1. How can i preform similar operation (SELECT Query) in J2ME RMS database? Is there any other way for me to achieve the above SQL statement?
2. The Filter option from J2me, am i right that it's only useful when you wish to search a single text ONLY?
3. Can you suggest any other useful URL for my as a reference code? I am a beginner in J2ME and notice it's kind of "restricted" as mostly many classes is not available.

Thank you.

Question by:taiping
    LVL 5

    Assisted Solution

    dear. RMS is not the RELATIONAL DATABASE.

    anyways i tel you about how u can handel the record in RMS.

     its just a simple way to store your data in mobiles.
    each transaction is stores as a record in RMS, which is stors like , u can say list or array:P (because it has no rows and cols).
    and there are no sql queries supported in j2me.

    your must read the record (rms) and then find compare that with your required string/data.

    hope you have the solution to your problem.

    one more thing, there is a size limitation of RMS, which varies from phone to phone and available memory.

    Kind Regards,
    LVL 12

    Accepted Solution

    You will not be able to run SQL statements in J2ME on the RecordStore. THe recordstore only stores all the data as separate records.
    You need to formulate a way to store all the data (which means that you could either store each tuple in your db as separate rows, or you could store all of them in a single record).

    You will need to implement the complete mechanism to read (and write) all the bytes from the recordstore, interpret them as required and then use the data. You can even skip the RecordFilter and do it yourself.

    It makes more sense to build something like a DAO (Data Access Object) and store the object. The object will internally have store() and read() methods which will know how to write to and read from the RecordStore.
    LVL 5

    Assisted Solution

    here is the example,

    you will come to know how you can play with RMS in j2me and use it for your purposes.

    kind Regards,
    LVL 15

    Assisted Solution

    If you're still looking for a solution to this and you really want to use SQL, you could try Pointbase

    I haven't personally used it, but the datasheet describes some quite impressive features and they do have an evaluation version available.


    Assisted Solution

    DataMirror company provides PointBase Micro database for J2ME

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now