开发者

Case-insensitive Query

I have some ticket numbers that may have numbers and let开发者_如何学JAVAters mixed. I'll be passing in the ticketNumberIds into this method (user input) and I want it to query against the Oracle database and have the query pick up tickets that differ by upper and lower cases.

How do I make the following a case-insensitive query?

public List<TicketDO> getTicketDOsById(final List<String> ticketNumberIds) {

    String myQuery = "from TicketDO t where t.ticketNumberId in (:ticketNumberIds)";

    return getEntityManager().createQuery(myQuery).setParameter("ticketNumberIds", ticketNumberIds)
    .getResultList();

}


You can use UPPER to perform case insensitive queries.

public List<TicketDO> getTicketDOsById(final List<String> ticketNumberIds) {

    String myQuery = "from TicketDO t where UPPER(t.ticketNumberId) in (:ticketNumberIds)";
    List<String> upperNumbers = new ArrayList<String>();
    for (String number : ticketNumberIds) {
        upperNumbers.add(number.toUppercase());
    }
    return getEntityManager().createQuery(myQuery).setParameter("ticketNumberIds", upperNumbers)
    .getResultList();

}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜