UcanaccessSQLException: UCAExc:::3.0.1 data type o

2019-07-13 03:19发布

I have a table like the following image

enter image description here

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条回答
Explosion°爆炸
2楼-- · 2019-07-13 03:41

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.

查看更多
登录 后发表回答