Q:

SQL fuzzy search

I have to call SQL database search in my Java program. 
The retrieving condition is that user input string partially matches NAME filed and not case sensitive. For example, if user input "joe", students' records with name like "Joea", "Bjoe","JOEED" should be returned. 
While I tried to write code as bellow. It doesn't seem to be able to work out. 
Can someone tell me why? Thanks.
String fuzzySearch = "UPPER(%" + inputStr + "%)";
String query = "SELECT * FROM student WHERE UPPER(student.name) LIKE ? ";
PreparedStatement prepStatement = con.prepareStatement(query.toString());
prepStatement.setObject(1,fuzzySearch);

A:

As you are using a string bind variable, you are saying
WHERE UPPER(student.name) LIKE 'UPPER(%joe%)'

instead of
WHERE UPPER(student.name) LIKE UPPER('%joe%')

So use
String fuzzySearch = "%" + inputStr + "%";
String query = "SELECT * FROM student WHERE UPPER(student.name) LIKE UPPER(?) ";
PreparedStatement prepStatement = con.prepareStatement(query.toString());
prepStatement.setObject(1,fuzzySearch);

instead.

