Database query j2me including criterias

2019-07-18 23:34发布

I am creating an application with J2ME. for connecting with database i am using RecordStore.

so to get a record i need to write as follow:

public boolean SearchRecord(String Rec, int pos )
    {
        String [] data = getRecordData();

        Rec = Rec.substring(0,pos);
        for ( int i = 0 ; i < data.length ; i++ )
        {
            data[i] = data[i].substring(0, pos );
            if ( Rec.toString().trim().equals(data[i].toString().trim()) )
            {
                data = null; // System.gc();
                return true;
            }
        }

        data = null; // System.gc();
        return false;
    }

This is first get all records and traverse through it to search a record. But i have thousands of records and i just need some based on criteria is there any way to resolve this problem ? I do not want to traverse through thousands of records to get ten records.

One more thing i am confused about UI part that LWUIT is better or JSR is better to implement ?

2条回答
男人必须洒脱
2楼-- · 2019-07-18 23:39

If you are calling SearchRecord a lot you could make String [] data an attribute. This would lead to a smaller version of your method:

public boolean SearchRecord(String rec, int pos )
{
    rec = rec.substring(0, pos).trim();
    for ( int i = 0 ; i < this.data.length ; i++ )
    {
        String comp = this.data[i].substring(0, pos);
        if ( rec.equals(comp.trim()) )
        {
            return true;
        }
    }

    return false;
}
查看更多
干净又极端
3楼-- · 2019-07-18 23:42

The code you are talking in the question is method from my answer. I have developed this code about a year ago for searching purpose only. The basic of RMS is a structured version of flat file. You can not fire a query on RMS. There is no in-built method for searching records from RMS. This is the reason that after many r & d i developed the above code.

查看更多
登录 后发表回答