简体   繁体   English

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

[英]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);

streamsequence字段定义为UUID类型

暂无
暂无

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

相关问题 com.datastax.driver.core.exceptions.InvalidQueryException:未配置的表用户” - com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table user" 使用Datastax Java驱动程序的com.datastax.driver.core.exceptions.InvalidQueryException - com.datastax.driver.core.exceptions.InvalidQueryException using Datastax Java driver com.datastax.driver.core.exceptions.InvalidQueryException:未配置的表schema_keyspaces - com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table schema_keyspaces com.datastax.driver.core.exceptions.InvalidQueryException: 未配置表 peers_v2 - com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table peers_v2 卡桑德拉数据库。 com.datastax.driver.core.exceptions.InvalidQueryException:未配置的表人 - Cassandra DB. com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table person com.datastax.driver.core.exceptions.InvalidQueryException:在SET部分中找到的PRIMARY KEY部分序列 - com.datastax.driver.core.exceptions.InvalidQueryException: PRIMARY KEY part sequence found in SET part 引起:com.datastax.driver.core.exceptions.InvalidQueryException:日期 (25) 的预期长度为 8 或 0 字节 - Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Expected 8 or 0 byte long for date (25) 线程“ main”中的异常com.datastax.driver.core.exceptions.InvalidQueryException:PRIMARY KEY中引用的未知定义 - Exception in thread “main” com.datastax.driver.core.exceptions.InvalidQueryException: Unknown definition referenced in PRIMARY KEY com.datastax.driver.core.exceptions.InvalidQueryException:对于PRIMARY KEY部分无效的运算符IN - com.datastax.driver.core.exceptions.InvalidQueryException: Invalid operator IN for PRIMARY KEY part 引起:com.datastax.driver.core.exceptions.InvalidQueryException:对于date(13),预期长度为8或0字节 - Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Expected 8 or 0 byte long for date (13)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM