Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search text problem

Status
Not open for further replies.

deddleston

Programmer
Oct 4, 2002
43
0
0
GB
i have a jsp webpage (search engine) when searching for text e.g;

CUST i need the results to include -

CUST
Cust
cust

do you know what i mean... any help much appreciated.

M$ arn't the only option!
 
Assuming you're searching against a database and that the form on the JSP page invokes a servlet, you'll need to do something like the following:

In the servlet doGet/doPost method(s):

// get search term from HTML form
String searchTerm = request.getParameter("searchTerm");
if (searchTerm == null) {
searchTerm = "";
}

// Build SQL SELECT query (exact match)
String sqlQuery = "SELECT * FROM SomeDatabaseTable WHERE LOWER(SomeColumn) = '" + searchTerm.toLowerCase() + "' "

or if you need to get similar matches then try something like

// Build SQL SELECT query (similar match)
String sqlQuery = "SELECT * FROM SomeDatabaseTable WHERE LOWER(SomeColumn) LIKE '" + searchTerm.toLowerCase() + "%' "

Note: '%' may not be the correct wildcard character for the database you're using. Also, your database may or may not support the LIKE operator. And LOWER may or may not be the correct name of your database's string function to convert to lowercase.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top