How to write a search method include "Like" such as SQL in J2ME
Now I try to write a small method to search in j2me, i开发者_JAVA百科t works well but I don't know how to write a method like SQL use "Like" in j2me to search recordstore doesn't need match 100% percent.
Example
In my RecordStore there are 2 records
London; Paris; Atlanta;
Paramount; NewYork; Bronx;
When I type on TextField letter "o" it only shows last record
Paramount; NewYork; Bronx
although first record also has "London"
I learned how to write a search method from Java2s dot com
http://www.java2s.com/Tutorial/Java/0430__J2ME/SearchrecordinRecordStore.htm
How to use "Like" in J2me?
(expanding on what was discussed in question comments)
Regarding your general question - the answer is no, MIDP 2 API has nothing like SQL LIKE. SQL expressions/statements cannot be used according to RecordStore API.
The way to to search MIDP RecordStore for inexact match (similar to SQL LIKE
) is to process the records using regular expressions. Note that regular expressions, in turn, are also not available in MIDP 2 API.
To use regular expressions in MIDP, one would have to write own code for these, or better yet, get some library that does that, eg "regexp-me" open source package:
"Java Me (j2me) regular expression package based on Jakarta Regexp. Regexp-me is CLDC1.0 compatible and has partial Unicode support".
As for the example SearchrecordinRecordStore.htm you mention, it looks like if you correctly ported it then you should get "London".
- I mean if your
RecordFilter
passes at strings containing "o" (case insensitive) and if you enumerated records using that filter then "London" should be there in the enumeration.
Check if you somehow missed "London" when doing the output (btw original example seem to be targeted at displaying a single result). If you use emulator, consider usingSystem.out.println
- that way you could re-check the output not only with MIDlet UI but in emulator console.
精彩评论