Answer the question
In order to leave comments, you need to log in
How to organize a search in the database?
It is necessary to organize a search for strings in the MySQL database, but the query will contain only a substring.
That is, there is a database. It contains the id and name fields. Name contains a string of 2-3 words.
And I need to select all rows containing the substring specified in the request, organizing this in java.
Mysql, as far as I know, has built-in support for regular expressions ( RLIKE 'word')
But for some reason it doesn't work like this:
try(PreparedStatement ps = DBConnector.getConnection().prepareStatement("SELECT * FROM items WHERE 'name' RLIKE ?")) {
ps.setObject(1,searchPattern.getName());
}
Answer the question
In order to leave comments, you need to log in
Maybe it's easier like this?SELECT * FROM items WHERE 'name' LIKE '%?%'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question