很抱歉再次发布同样的问题,但我很想知道。
我想知道我们如何将 java 中的当前日期与 mysql 中存储的日期进行比较。
存储在 MySQL 中的日期是2013-01-04 13:15:00
当我通过获取当前日期在java中比较这个日期时
Date date = new Date();
然后写一个查询,如果存储在 MySQL 中的日期小于当前显示结果。但查询在列表中返回 0 结果或异常我已在最后粘贴异常。
select model from abc model where model.abcStartDate <= :? and model.abcEndDate >= :?
在 ”:?” date 是通过 MySQL 中的开始日期和结束日期是时间戳数据类型的。
下面是EJB实体类
@Entity
@Table(name = "abc_table", uniqueConstraints = {})
public class ABCClass implements java.io.Serializable {
private static final long serialVersionUID = -1924961655993587546L;
// Fields
private Date abcStartDate;
private Date abcEndDate;
// Constructors
/** default constructor */
public ABCClass() {
}
@OrderBy(value="3")
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "abc_start_date", unique = false, nullable = false, insertable = true, updatable = true, length = 19)
public Date getabcStartDate() {
return this.abcStartDate;
}
public void setabcStartDate(Date abcStartDate) {
this.abcStartDate = abcStartDate;
}
@OrderBy(value="4")
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "abc_end_date", unique = false, nullable = false, insertable = true, updatable = true, length = 19)
public Date getabcEndDate() {
return this.abcEndDate;
}
public void setabcEndDate(Date abcEndDate) {
this.abcEndDate = abcEndDate;
}
}
它抛出一个异常
Exception thrown from bean; nested exception is: Exception [EclipseLink-3001] (Eclipse Persistence Services - 2.2.1.v20110722-r9776): org.eclipse.persistence.exceptions.ConversionException
Exception Description: The object [65464533565], of class [class java.lang.String], could not be converted to [class java.lang.Integer].
Internal Exception: java.lang.NumberFormatException: For input string: "65464533565"