[英]Cassandra date insert from Java Spring Project
To the type date in cassandra database I would like to insert a value. 对于cassandra数据库中的date类型,我想插入一个值。 I tried with types java.util.Date and com.datastax.driver.core.LocalDate. 我尝试使用java.util.Date和com.datastax.driver.core.LocalDate类型。 Both ways don't work for me. 两种方式都不适合我。 For LocalDate error: 对于LocalDate错误:
"JSON parse error: Can not construct instance of com.datastax.driver.core.LocalDate: no String-argument constructor/factory method to deserialize from String value (''); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.datastax.driver.core.LocalDate: no String-argument constructor/factory method to deserialize from String value ('')\n at [Source: java.io.PushbackInputStream@4d549b00; line: 10, column: 25] (through reference chain: com.comarch.programs.dtos.ProgramDto[\"prgStartDate\"])",
Date error: 日期错误:
"Expected 4 byte long for date (8); nested exception is com.datastax.driver.core.exceptions.InvalidQueryException: Expected 4 byte long for date (8)"
You can do the following way: 您可以通过以下方式进行操作:
private Date accessDate;
@Transient
private Date activeDate;
public Date getActiveDate() {
return activeDate;
}
public void setActiveDate(Date activeDate) {
SimpleDateFormat sp1 = new SimpleDateFormat("yyyyy-MM-dd hh:mm:ss+0000");
String strDate = sp1.format(activeDate);
try {
this.activeDate = sp1.parse(strDate);
setAccessDate(new java.sql.Timestamp(this.activeDate.getTime()));
} catch (ParseException e) {
e.printStackTrace();
}
}
Use a transient data to format the date accordingly and set the date using java.sql.Timestamp 使用瞬态数据来相应地格式化日期,并使用java.sql.Timestamp设置日期
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.