开发者

LIKE in SQL work incorrectly?

开发者 https://www.devze.com 2023-03-03 18:32 出处:网络
In my ejb-jar.xml <query> <query-method> <method-name>findByCaName</method-name>

In my ejb-jar.xml

       <query>
            <query-method>
                <method-name>findByCaName</method-name>
                <method-params>
                    <method-param>java.lang.String</method-param>
                </method-params>
            </query-method>
            <ejb-ql>SELECT OBJ开发者_StackOverflowECT(c) FROM Categories AS c WHERE c.caName LIKE ?1</ejb-ql>
        </query>

When I searched, for examples, "Action" , the result is correct, but when I tried finding "Acti", it returned a null collection, can anybody tell me where I were wrong?

Thank you


Usually you have to specify wildcards in your like string, such as "Acti%" or "%cti%"


How about appending a % to your parameter:

CONCAT(?1, '%')


Let your parameter be a string and then append '%' or '_' as prefix or suffix. '_' refers for a single character variation, and '%' stands for multiple character variation.

But the coolest way is to let user[in a searching functionality] to enter % or _ in and then pass it to query. This gives a huge advantage and flexibility.

0

精彩评论

暂无评论...
验证码 换一张
取 消