UcanaccessSQLException: UCAExc: 3.0.1 expression data type is not logical

I have a table, for example, the following image

enter image description here

I need to get all the English words that his Kurdish word contains "بةرز",
Therefore i cannot use

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

because he also accepts words that are a substring in another word like these, يبلبةرز, سيس بةرز,
And when I try to use the regex in my query:

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

It displays the following exception

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

Is there a problem with my regex or what? Please note that I am using UCanAccess to connect to the database

+2
source share
1 answer

Instead

 columnName REGEXP 'pattern' 

I believe you need to use

 REGEXP_MATCHES(columnName, 'pattern') 

It 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 may be a more elegant way to do this.

+2
source

All Articles