UcanaccessSQLException: UCAExc:::3.0.1 data type of expression is not boolean

只愿长相守 提交于 2019-12-11 01:36:24

问题


I have a table like the following image

I need to get all the English words that its Kurdish Word contains "بةرز",
So i cant use

select English from Table1 where Kurdish like '%بةرز%';

because it also accepts the words that are sub-string in another word like these ،يبلبةرز ، سيس بةرز ,
And when i try to use Regular Expression in my query:

query = "SELECT English FROM Table1 WHERE Kurdish REGEXP '^[.، ]*("+"بةرز" +")[ ،.]*$'";
s.execute(query);


it shows the following Exception

net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.1 data type of expression is not boolean

Is the problem is with my regular expression or what?
Note that i'am using UCanAccess for my database connection


回答1:


Instead of

columnName REGEXP 'pattern'

I believe you need to use

REGEXP_MATCHES(columnName, 'pattern')

This seems to work for me ...

String targetString = "بةرز";
try (PreparedStatement ps = conn.prepareStatement(
        "SELECT English FROM Table1 " +
        "WHERE Kurdish = ? " +
            "OR REGEXP_MATCHES(Kurdish, ?) " +
            "OR REGEXP_MATCHES(Kurdish, ?) " +
            "OR REGEXP_MATCHES(Kurdish, ?) ")) {
    ps.setString(1, targetString);
    ps.setString(2, "^" + targetString + "[.، ]+.*");
    ps.setString(3, ".*[.، ]+" + targetString + "$");
    ps.setString(4, ".*[.، ]+" + targetString + "[.، ]+.*");
    try (ResultSet rs = ps.executeQuery()) {
        while (rs.next()) {
            System.out.println(rs.getString(1));
        }
    }
}

... although there might be a more elegant way of doing it.



来源:https://stackoverflow.com/questions/33282360/ucanaccesssqlexception-ucaexc3-0-1-data-type-of-expression-is-not-boolean

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