A.G
A.G

Reputation: 549

REGEXP in java code

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

Answers (1)

Hugo G
Hugo G

Reputation: 16536

Some errors I see here.

  1. You are using different variables:

    nativeSqlSerach
    

    and

    nativeSqlForSearch
    
  2. 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().

  3. 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

Related Questions