How to use * as a wild card in SQL query safely

Viewed 1120

I need to implement a search where user can input * as a wild card. The database they are searching is a SQL server. I was thinking of just replacing the * with a %:

userInput = userInput.replace('*', '%');

I'm worried that since I'm doing this "by hand" I might introduce some bugs or security flaws. Do you see any problems doing it like this? Is there any library to do this for me?

I use Hibernate as an ORM mapper and Criteria API to create the query if it helps with answers.

2 Answers
Related