• Post Reply Bookmark Topic Watch Topic
  • New Topic

basic search - help  RSS feed

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ive been implementing a basic search function which given a specified keyword searching a column in a database for records that contain the keyword. problem is the search is case sensitive and does not take into consideration that the keyword may be a substring.

for instance, forename = David
will only return this record if you specify "David"
"david, dav" does not work but i want it to.
any advice?

at the moment i am using string.contentsEquals(stringbuffer) for my evaluations, ive had a look through the API and cannot find much to help me

thanks
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you basically comparing two Strings to see if they are the same, despite differences in capitalisation, or where one starts with the value of the other? There are methods on the String class that do this. Also, if your passing the String 'dav' to an SQL statement, you could use the sql 'like' command. Oracle also has an UPPER statement you could use.

hope this helps
 
Deyna Cegielski
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
would like the case to be case insensitive, and to be able to type in a substring of a word and return all results containing that substring. i completely forgot about the like cause in mysql (not used it in a while) i shall have a look in my book see what i can do with it.
 
Alana Sparx
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect that you'll also want to determine if the flavour of SQL you're using supports an 'UPPER' clause. That way you can do your search in one statement.

Otherwise, you'll need to change the case of your search string (using the appropriate String API methods) and perform:
a search for the String as passed in;
a search in lowercase;
a search in uppercase;
title case?
random case?
arrrgggg!!
 
Deyna Cegielski
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hehe, its all sorted, thanks for the help!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!