suhail,
I can only give you a partial answer, which is based on the way that SQL works, you'll have to get the rest of the answer on how to do this in JAVA, from another source. However, I can at least give you enough information to help compose a question to that other person. I also hope that I'm not insulting your intelligence with this reply, please forgive me if I am over simplifying.
First, when using the LIKE predicate, one has to be sure that you know that this is a
pattern search process and not looking for and exact match (equality), which is a different predicate. Therefore, the pattern being used should contain either the underscore "_" which means look for any single character in that position, or use the percent sign "%", which means look for any number of characters (even zero characters) of any character in that position coded in the pattern.
Additionally, be aware of the fact that the non-pattern characters included in the
string ARE case sensetive.
Where lastname LIKE '%SON'.
Will find: JOHNSON, ANDERSON, WESSON, and so on.
It will NOT find: johnson, anderson, ... and so on because of the case.
Secondly, some DBMS (Data Base Management Systems) don't use the % or _, but other characters, you'll have to check their
doc for confirmation.
Thirdly, the
test for whether or not the query finds any results will depend on the implementation of how you search. When I code non-Java programs (because I'm going through a great learning curve in JAVA and it's quite new to me), in other languages and platforms, I test for the results to come back from the server in either SQLCODE or SQLSTATE.
SQLCODE is a large integer, SQLSTATE is a character (5) field, both return a value that describes what happened in the last SQL statement you executed.
SQLCODE = 0 -- everything worked ok
SQLCODE < 0 -- an error, probably with some diagnostics
SQLCODE > 0, but not +100 - an SQL WARNING (it worked, but it wants to tell you about it with a qualification, usually, not to worry)
SQLCODE +100 - no more data to be returned (like end of file condition) or no data found in the first place.
SQLSTATE '00xxx' -- Unqualified success.
SQLSTATE '01xxx' -- Warning
SQLSTATE '02xxx' -- No data returned,
Then there are bunches of other prefix codes that imply all kinds of categories of errors.
I'd recommend test for the code then determine, in the logic of your program to issue the prompt... now, I return you back to your JAVA code issue.
Regards,
Gary J.
Colo Spgs, CO