Datastax Cassandra Driver throwing CodecNotFoundException
When you call bind(params...)
on a PreparedStatement
the driver expects you to provide values w/ java types that map to the cql types.
This error ([timestamp <-> java.lang.String]
) is telling you that there is no such Codec registered that maps the java String
to a cql timestamp
. In the java driver, the timestamp
type maps to java.util.Date
. So you have 2 options here:
- Where the column being bound is for a timestamp, provide a
Date
-typed value instead of aString
. - Create a codec that maps
timestamp <-> String
. To do so you could create sub class ofMappingCodec
as described on the documentation site, that maps String to timestamp:
public class TimestampAsStringCodec extends MappingCodec<String, Date> {
public TimestampAsStringCodec() { super(TypeCodec.timestamp(), String.class); }
@Override
protected Date serialize(String value) { ... }
@Override
protected String deserialize(Date value) { ... }
}
You then would need to register the Codec:
cluster.getConfiguration().getCodecRegistry()
.register(new TimestampAsStringCodec());