[英]Query fails with “com.datastax.driver.core.exceptions.InvalidQueryException: String didn't validate.”
I have a table created like this: 我有一个这样创建的表:
CREATE TABLE messages (
stream int,
sequence int,
timestamp bigint,
message blob,
PRIMARY KEY (stream, sequence)
) WITH gc_grace_seconds = 0;
Running the following query in CQLSH works perfectly fine: 在CQLSH中运行以下查询非常正常:
select * from messages where stream = 1 and sequence >= 1 and sequence <= 100;
However, when I try to run the same via Java driver I get the following exception: 但是,当我尝试通过Java驱动程序运行相同代码时,出现以下异常:
com.datastax.driver.core.exceptions.InvalidQueryException: String didn't validate.
at com.datastax.driver.core.exceptions.InvalidQueryException.copy(InvalidQueryException.java:35)
at com.datastax.driver.core.ResultSetFuture.extractCauseFromExecutionException(ResultSetFuture.java:271)
at com.datastax.driver.core.ResultSetFuture.getUninterruptibly(ResultSetFuture.java:187)
at com.datastax.driver.core.Session.execute(Session.java:126)
at com.datastax.driver.core.Session.execute(Session.java:100)
I'm using parameterized querying API: 我正在使用参数化查询API:
public final String FETCH_CQL = "select stream, sequence, timestamp, message "
+ "from messages where stream = ? and sequence >= ? and sequence <= ?";
session.execute(FETCH_CQL, Integer.parseInt(stream), Integer.parseInt(fromSequence), Integer.parseInt(toSequence));
What gives? 是什么赋予了? Overall setup works, as I have another query working on a different table. 总体设置有效,因为我在另一个表上有另一个查询。
Thanks! 谢谢!
Have you tried adding ; 您是否尝试过添加; to the end of your query: 到查询末尾:
public final String FETCH_CQL = "select stream, sequence, timestamp, message "
+ "from messages where stream = ? and sequence >= ? and sequence <= ?**;**";
Another option is to use prepared statements: 另一种选择是使用准备好的语句:
PreparedStatement FETCH_PS = session.prepare(FETCH_CQL);
BoundStatement boundStatement = FETCH_PS.bind(Integer.parseInt(stream), Integer.parseInt(fromSequence), Integer.parseInt(toSequence));
session.execute(boundStatement);
将stream
和sequence
字段定义为UUID
类型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.