简体   繁体   English

引起: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)

I developing application using Cassandra and SpringBoot.我使用 Cassandra 和 SpringBoot 开发应用程序。 I have written Cassandra query in Java;我用 Java 编写了 Cassandra 查询;

String userName="testUser";
String lastUpdatedDate="2018-11-29 13:00:43.400";
String tenantName="demo";

Select select = QueryBuilder.select().all()
                    .from(tenantName,getGenericClass().getSimpleName())
                    .where(QueryBuilder.eq("user_Name", userName))
                    .and(QueryBuilder.gt("last_updateddate",  lastUpdatedDate))
                    .allowFiltering()
                    .limit(100);
           return (List<T>) cassandraOperations.select(select, getGenericClass());

last_updateddate is timestamp data type column in Cassandra. last_updateddate 是 Cassandra 中的时间戳数据类型列。 userName and last_updateddate columns are composite key in database and using latest version of Cassandra. userName 和 last_updateddate 列是数据库中的组合键,使用最新版本的 Cassandra。

while executing getting the following error.执行时出现以下错误。

Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Expected 8 or 0 byte long for date (25)引起:com.datastax.driver.core.exceptions.InvalidQueryException:日期 (25) 的预期长度为 8 或 0 字节

but

Issue got resolved after below change.以下更改后问题得到解决。

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));

Date date = sdf.parse(lastUpdatedDate);
long timeInSec = date.getTime();

Timestamp ts=new Timestamp(timeInSec);  
Date date1=ts;                                                                                                         
 Select select = QueryBuilder.select().all()
                        .from(tenantName,getGenericClass().getSimpleName())
                        .where(QueryBuilder.eq("user_Name", userName))
                        .and(QueryBuilder.gt("last_updateddate",  date1))
                        .allowFiltering()
                        .limit(100);
               return (List<T>) cassandraOperations.select(select, getGenericClass());

you have to check data type of Cassandra table and use corresponding datatype of java and use it in java code when declaring variable to pass value of column .您必须检查 Cassandra 表的数据类型并使用相应的 java 数据类型,并在声明变量以传递列值时在 java 代码中使用它。

Example : In Cassandra LocalDate then define LocalDate of cassandra.core package in java instead Date or LocalDate of util package.示例:在 Cassandra LocalDate 中,然后在 java 中定义 cassandra.core 包的 LocalDate 而不是 util 包的 Date 或 LocalDate。

check this type mapping between Cassandra vs Java检查Cassandra 与 Java 之间的这种类型映射

暂无
暂无

声明:本站的技术帖子网页,遵循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:未配置的表人 - Cassandra DB. com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table person 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 线程“ 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.SyntaxError:行0:-1输入不匹配&#39; <EOF> &#39;期待&#39;)&#39; - Caused by: com.datastax.driver.core.exceptions.SyntaxError: line 0:-1 mismatched input '<EOF>' expecting ')' 我应该为“ com.datastax.driver.core.exceptions.ReadTimeoutException”做什么? - what should I do for “com.datastax.driver.core.exceptions.ReadTimeoutException”? Cassandra-com.datastax.driver.core.exceptions.DriverException:尝试获取可用连接时超时 - Cassandra - com.datastax.driver.core.exceptions.DriverException: Timeout while trying to acquire available connection 我们如何将 com.datastax.driver.core.LocalDate 转换为 java.util.Date? - How can we convert com.datastax.driver.core.LocalDate to java.util.Date?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM