繁体   English   中英

查询失败,并显示“ com.datastax.driver.core.exceptions.InvalidQueryException:字符串未验证。”

[英]Query fails with “com.datastax.driver.core.exceptions.InvalidQueryException: String didn't validate.”

我有一个这样创建的表:

CREATE TABLE messages (
stream int,
sequence int,
timestamp bigint,
message blob,
PRIMARY KEY (stream, sequence)
) WITH gc_grace_seconds = 0;

在CQLSH中运行以下查询非常正常:

select * from messages where stream = 1 and sequence >= 1 and sequence <= 100;

但是,当我尝试通过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)

我正在使用参数化查询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));

是什么赋予了? 总体设置有效,因为我在另一个表上有另一个查询。

谢谢!

您是否尝试过添加; 到查询末尾:

public final String FETCH_CQL = "select stream, sequence, timestamp, message "
            + "from messages where stream = ? and sequence >= ? and sequence <= ?**;**";

另一种选择是使用准备好的语句:

PreparedStatement FETCH_PS = session.prepare(FETCH_CQL);
BoundStatement boundStatement = FETCH_PS.bind(Integer.parseInt(stream), Integer.parseInt(fromSequence), Integer.parseInt(toSequence));
session.execute(boundStatement);

streamsequence字段定义为UUID类型

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM