I have a table in Cassandra which I am trying to iterate and extract stuff from it. I am using datastax java driver 3.1.0.
CREATE TABLE test (
client_id int,
process_id text,
last_modified_date timestamp,
PRIMARY KEY ((client_id), process_id)
)
Below is the code:
private List<MetaHolder> getMetaHolder() {
List<MetaHolder> metaHolder = new ArrayList<>();
String sql = "select * from test where client_id=1";
try {
BoundStatement bs = Cache.getInstance().getStatement(sql);
bs.setConsistencyLevel(ConsistencyLevel.QUORUM);
ResultSet res = session.execute(bs);
Iterator<Row> rows = res.iterator();
while (rows.hasNext()) {
Row row = rows.next();
String processId = row.getString("PROCESS_ID");
// this line throws exception
UUID lastModifiedDate = row.getUUID("LAST_MODIFIED_DATE");
MetaHolder metadata =
new MetaHolder(processId, lastModifiedDate);
metaHolder.add(metadata);
}
} catch (Exception ex) {
LOGGER.logError("error= ", ExceptionUtils.getStackTrace(ex));
}
return metaHolder;
}
Below is the exception:
error= com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: [timestamp <-> java.util.UUID]
Is there any way I can use JodaTime by creating a codec if possible instead of using UUID here in my code?
Change the below code
UUID lastModifiedDate = row.getUUID("LAST_MODIFIED_DATE");
to
Date lastModifiedDate = row.getTimestamp("LAST_MODIFIED_DATE");
You can get joda DateTime from Date
DateTime lastModifiedDateTime = new DateTime(lastModifiedDate);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.