如何在 java 中获取 cql 日期?
How to get cql date in java?
我在我的应用程序中使用 java8 和 cassandra。 cassandra table中current_date的数据类型是'date'。我正在使用 java 中的实体映射到 table 值。实体中同一字段的数据类型为 java.sql.Date.
当我尝试检索记录 'Select * from table where current_date='2017-06-06';'我收到以下错误'
`Caused by: com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: ['org.apache.cassandra.db.marshal.SimpleDateType' <-> java.sql.Date]
我尝试过各种数据类型,例如:
com.datastax.driver.core.LocalDate, java.util.Date
,com.google.common.reflect.TypeToken
所有人都返回相同的错误。
我提到了 http://docs.datastax.com/en/developer/java-driver/3.1/manual/custom_codecs/extras/。
但我卡住了。请帮帮我。
默认情况下,Java 驱动程序会将 date
类型映射到 com.datastax.driver.core.LocalDate
Java 类型。
如果您需要将 date
转换为 java.time.LocalDate
,那么您需要向您的项目添加额外的内容并按照文档中的说明全局注册编解码器:
cluster.getConfiguration().getCodecRegistry()
.register(LocalDateCodec.instance);
或者您可以仅为给定的列指定编解码器:
@Column(codec = LocalDateCodec.class)
java.time.LocalDate date;
同样,可以转换为 Joda 时间类型。
我在我的应用程序中使用 java8 和 cassandra。 cassandra table中current_date的数据类型是'date'。我正在使用 java 中的实体映射到 table 值。实体中同一字段的数据类型为 java.sql.Date.
当我尝试检索记录 'Select * from table where current_date='2017-06-06';'我收到以下错误'
`Caused by: com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: ['org.apache.cassandra.db.marshal.SimpleDateType' <-> java.sql.Date]
我尝试过各种数据类型,例如:
com.datastax.driver.core.LocalDate, java.util.Date ,com.google.common.reflect.TypeToken
所有人都返回相同的错误。
我提到了 http://docs.datastax.com/en/developer/java-driver/3.1/manual/custom_codecs/extras/。
但我卡住了。请帮帮我。
默认情况下,Java 驱动程序会将 date
类型映射到 com.datastax.driver.core.LocalDate
Java 类型。
如果您需要将 date
转换为 java.time.LocalDate
,那么您需要向您的项目添加额外的内容并按照文档中的说明全局注册编解码器:
cluster.getConfiguration().getCodecRegistry()
.register(LocalDateCodec.instance);
或者您可以仅为给定的列指定编解码器:
@Column(codec = LocalDateCodec.class)
java.time.LocalDate date;
同样,可以转换为 Joda 时间类型。