1

Now I try to write a small method to search in j2me, it 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?

gnat
  • 6,213
  • 108
  • 53
  • 73
MYE
  • 983
  • 8
  • 24
  • 41
  • 1
    You need regular expressions for this task. Check "regexp-me" package: http://code.google.com/p/regexp-me/ –  Sep 29 '11 at 07:42
  • Thank you ! Buy in J2ME Does not has any way to write a code like SQL Statement? – MYE Sep 29 '11 at 08:55
  • 1
    SQL expressions/statements cannot be used according to RecordStore. –  Sep 29 '11 at 09:04
  • i know that but in Does J2ME has any method or way to do like that? – MYE Sep 29 '11 at 16:32
  • 1
    Process recordstore records with regular expressions as I mentioned before. There's no another way. –  Sep 29 '11 at 17:01
  • 1
    @RafaelOsipov if you copy your comments here into an answer I'll be the first to upvote – gnat Oct 09 '11 at 09:21
  • @gnat thank you. My answer with additional comments was converted to sequence of comments by a stackoverflow moderator. Here is the reason provided by moderator: http://stackoverflow.com/faq#deletion –  Oct 09 '11 at 09:48
  • @RafaelOsipov interesting. I haven't seen text of your answer so I can't comment really but if you feel strong about this conversion, consider discussing it at [meta](http://meta.stackoverflow.com/). Meanwhile I'll probably try to compile my version of the answer from your comments - I still believe these make quite a solid ground for that – gnat Oct 10 '11 at 06:12
  • @gnat Screenshot with my deleted answer is here: http://i.imgur.com/YmSWs.png Feel free to compose a solid answer using my comments. –  Oct 10 '11 at 17:00
  • 1
    @RafaelOsipov thanks! I updated [the answer](http://stackoverflow.com/questions/7593763/how-to-write-a-search-method-include-like-such-as-sql-in-j2me/7714277#7714277) based on that screen shot – gnat Oct 10 '11 at 17:45

1 Answers1

1

(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 using System.out.println - that way you could re-check the output not only with MIDlet UI but in emulator console.
gnat
  • 6,213
  • 108
  • 53
  • 73