简体   繁体   中英

java.sql.Time : insert current time correctly

I'm trying to insert current time into a java.sql.Time field, but I get this exception:

default message [Failed to convert property value of type 'java.lang.String' to required type 'java.sql.Time' for property 'entryDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.sql.Time] for value ''; nested exception is java.lang.IllegalArgumentException]

This is the code:

firm.setEntryDate(Time.valueOf(java.time.LocalDate.now().toString()));

Can anybody please advise what I am doing wrong? Thanks!

Update: Firm.class

@JsonProperty("webshow")
private String webShow;
private Time entryDate;

public String getWebShow () {
    return webShow;
}

public void setWebShow (String webShow) {
    this.webShow = webShow;
}

public Time getEntryDate () {
    return entryDate;
}

public void setEntryDate (Time entryDate) {
    this.entryDate = entryDate;
}

Full exception:

 Resolved exception caused by Handler execution: org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'firm' on field 'entryDate': rejected value []; codes [typeMismatch.firm.entryDate,typeMismatch.entryDate,typeMismatch.java.sql.Time,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [firm.entryDate,entryDate]; arguments []; default message [entryDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.sql.Time' for property 'entryDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.sql.Time] for value ''; nested exception is java.lang.IllegalArgumentException]

尝试这个:

firm.setEntryDate(java.sql.Time.valueOf(LocalTime.now()));

Use timeStamp

private TimeStamp entryDate;

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM