Click here to Skip to main content
14,870,660 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a search query which must search a column in a table using contains search. There is ctxsys.context type index on the column. While fetching data on the table using prepared statement, the search query is not able to process special characters like -,/,_ etc.

Here is my code -

String query = "select * from parties where contains (party_name ,'%' || ? || '%')";
PreparedStatement ps = con.prepareStatement(query);
ps.setString(1, searchName);
The code works fine for text which doesn't have special characters.

When I run the below query in sqlDeveloper it runs fine .

select * from parties where contains(party_name,'c/o')>0;
Please suggest what changes should I make in the prepared statement to make it work for special characters too.

What I have tried:

I have tried modifying the code to following but none worked-
String query = "select * from parties where contains (party_name ,'|| ? ||')";
String query = "select * from parties where contains (party_name ,?)";
String query = "select * from parties where contains (party_name ,||?||)";
String query = "select * from parties where contains (party_name ,'?')";
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900