开发者

LIKE in SQL work incorrectly?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜