Reputation: 549
This is the query which is running properly in sql . But when i am ruuning it with java code. Showing query syntax exception
SELECT * FROM faq WHERE question REGEXP 'general'
My java code
List<Object[]> results = getBaseDao().findByNativeSql(nativeSqlForSearch.toString(), 0,0);
where
StringBuilder nativeSqlSerach = "Select f from faq f where f.question REGEXP 'general' "
Upvotes: -1
Views: 54
Reputation: 16536
Some errors I see here.
You are using different variables:
nativeSqlSerach
and
nativeSqlForSearch
You are using a String as a StringBuilder object. This is just wrong and I wonder why it doesn't fail to compile. Either use
StringBuilder nativeSqlSerach = new StringBuilder("Select f from faq f where f.question REGEXP 'general'");
with toString()
later on, or
String nativeSqlSerach = "Select f from faq f where f.question REGEXP 'general'";
without toString()
.
I am not sure you have posted a simplified problem or not, but in the case described above you don't need any REGEX
at all. Just use =
or LIKE
wildcard notation.
Upvotes: 1