I have a query that is being used to pull usernames and info about the user. In Access I had the LIKE function so that the user didn’t have to type in a specific name. I am now transferring it over to JSP. Here is the line in the query that I am having troubles with in JSP:
WHERE ObjectName Like '" + "%"+ VariableName + "%" +"';
The query runs fine but does not show any information even if I put in the entire name. If I change it to:
WHERE ObjectName = '" + VariableName +"';
it works, but I would like to give the user a chance to have to ability to put in partial names in case they do not know how to spell the name or typ eit incorrectly. Any help would be apprecited.
Thanks
The line you’ve shown is a bit odd, but syntactically valid. So the problem lies somewhere else. What does
variableNameactually contain?That said, you shouldn’t be writing raw Java code in JSP files. Do that in a Java class. You can use a
Servletclass to preprocess or postprocess requests. Also grabPreparedStatementto avoid SQL injections. Here’s a kickoff example: