Case insensitive search in Java DB (Derby)

瘦欲@ 提交于 2019-12-07 03:16:28

问题


I'm using Derby and I can't find a way to do case insensitive search.

For example, I have a table that I'm searching that contains "Hello" but I put a search query in for "hello" and at the moment I won't get a result, but I want to.

I can't find the correct syntax for it.

Sara


回答1:


You can use the UPPER() or LOWER() SQL functions on both your search argument and the field, like in

SELECT *
FROM   mytab
WHERE  UPPER(lastname) = UPPER('McDonalds')



回答2:


The most common way to do this is to use generated columns. Here's a nice writeup from one of the Derby developers: http://blogs.oracle.com/kah/entry/derby_10_5_preview_generated




回答3:


This is really a late answer which I am not sure is the best way to manage the the process of doing a case insensitive search on a Textarea in a Derby Database
We added our search results to a TableView so if you get two results returned then the user has at least the option to decide which result is of value.

    String upper = "BIG";
    String lower = "big";
    ResultSet rs = stmnt.executeQuery("SELECT * FROM Child WHERE cEntry LIKE 
    '"+"%"+upper+"%"+"'OR cEntry LIKE'"+"%"+lower+"%"+"'");


来源:https://stackoverflow.com/questions/6084000/case-insensitive-search-in-java-db-derby

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!