Ignore case in JDO request

I would like to select a list of results from the database, but the statement ==for JDO queries is case sensitive. Is there a way to select "USER", "User" and "User" from the table using a single parameter?

In MySQL, you have a statement LIKE, and in Java, a function equalsIgnoreCase. However, none of them work in this example.

PersistenceManager pm = JDO.factory.getPersistenceManager();

Query query = pm.newQuery(User.class, "username == usernameParam");
query.declareParameters("String usernameParam");

List<User> results = (List<User>) query.execute(username);
+3
source share
2 answers

JDOQL has some String methods available. Check out the documentation here .

To fix the problem, you can do the following:

PersistenceManager pm = JDO.factory.getPersistenceManager();

Query query = pm.newQuery(User.class, "username.toUpperCase() == usernameParam");
query.declareParameters("String usernameParam");

List<User> results = (List<User>) query.execute(username.toUpperCase());
+4

- , , "" , . .

, " " .

+5

Source: https://habr.com/ru/post/1757287/


All Articles