【发布时间】:2016-11-03 02:44:31
【问题描述】:
Cassandra 3.4 现在通过自定义索引提供 LIKE 运算符。
在我使用 cqlsh 和 SELECT * FROM table WHERE indexed_column LIKE '%VALU%' 之类的东西的测试示例中,它运行良好。我已经建立了一个索引,它的所有功能都很完美。
如何在具有动态值的 Java 驱动程序(我使用的是 3.0.2 版)中执行此操作?我的查询使用 QueryBuilder 并在使用像这样的文字值时使用 PreparedStatements(PS 示例,但 QueryBuilder 也适用于文字值):
PreparedStatement ps = PreparedStatement("SELECT * FROM table WHERE indexed_column LIKE '%VALU%'");
但如果我想使用 ?在 QueryBuilder 或使用 PreparedStatements 中绑定一个值(例如绑定 '%VAL%')。例如
PreparedStatement ps = PreparedStatement("SELECT * FROM table WHERE indexed_column LIKE ?");
BoundStatement boundStatement = new BoundStatement(ps);
cassandraSession.execute(boundStatement.bind('%VAL%');
我收到以下错误:
com.datastax.driver.core.exceptions.SyntaxError: line 1:53 mismatched input '?' expecting STRING_LITERAL (...test.table WHERE indexed_column LIKE [?];)
【问题讨论】:
标签: java cassandra datastax datastax-java-driver