2017-08-07 18 views
0

要在cassandra数据库中输入日期,我想插入一个值。 我尝试过类型java.util.Date和com.datastax.driver.core.LocalDate。 这两种方式都不适合我。 对于LOCALDATE的错误:来自Java Spring Project的Cassandra日期插入

"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: [email protected]; line: 10, column: 25] (through reference chain: com.comarch.programs.dtos.ProgramDto[\"prgStartDate\"])", 

日期错误:

"Expected 4 byte long for date (8); nested exception is com.datastax.driver.core.exceptions.InvalidQueryException: Expected 4 byte long for date (8)" 

回答

0

你可以通过以下方式:

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(); 
    } 
} 

使用瞬态数据相应格式的日期和使用设置日期java.sql.Timestamp