aspose file tools*
The moose likes Performance and the fly likes how to achieve the Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "how to achieve the "like" effect of SQL in java" Watch "how to achieve the "like" effect of SQL in java" New topic
Author

how to achieve the "like" effect of SQL in java

giang nguyen
Ranch Hand

Joined: May 13, 2003
Posts: 42
Does any one know how to how to achieve the "like" effect of SQL in java ?
Specifically,how can I compare 2 string like the function like '%anotherString%' in SQL ?
The function returns true if the string is like '%another string%'
Thanks.


SCJP 1.4, SCWCD
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

You can use the java.util.regex package in JDK 1.4 to achieve this.


[Jess in Action][AskingGoodQuestions]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
This particular comparison is also easy to do with the indexOf() method which has been available in String since 1.0:

However the regex package will be far more powerful and flexible for other types of searches you may wish to provide, so it's definitely worth learning about.


"I'm not back." - Bill Harding, Twister
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
If you just want to do simple wildcard-style matching in a pre-1.4 virtual machine, you can implement a rough matcher without too much code. Here's an example of a function that will match a string against a pattern. Any occurences of the character '*' in the pattern can match 0 or more characters.
giang nguyen
Ranch Hand

Joined: May 13, 2003
Posts: 42
Thank you all for your advices. I've got it done !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to achieve the "like" effect of SQL in java
 
Similar Threads
search mechanism in java
how to run a function in PL/SQL from a java function....
in jsp i want touse java script variable value
how to run a function in PL/SQL from a java function....
Close a resultset in a function while returning the values