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 youUsually 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.
精彩评论