Database query j2me including criterias

a 夏天 提交于 2019-12-11 00:10:36

问题


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 ?


回答1:


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.




回答2:


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;
}


来源:https://stackoverflow.com/questions/11931780/database-query-j2me-including-criterias

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!