我是SpringBoot中的新成员,并使用嵌入式数据库H2创建应用程序。H2时间戳 - 始终插入(或获取)当前日期
CREATE TABLE IF NOT EXISTS t_occurrence (
id bigint PRIMARY KEY,
where varchar(100),
when timestamp null
);
我使用这个类来插入值,但无论我插入我总是得到当前的日期,当我做occurrence.getWhen()
int numOfRowsAffected = jdbcTemplate.update(
"insert into t_occurrence (ID, where, when) "
+ " values (?,?,?);",
id,
occurrence.getWhere(),
occurrence.getWhen()
);
if (numOfRowsAffected==1) return id;
else return -1;
即使硬编码的时间
int numOfRowsAffected = jdbcTemplate.update(
"insert into t_occurrence (ID, where, when) "
+ " values (?,?,''2012-09-17 18:47:52.69');",
id,
occurrence.getWhere(),
occurrence.getWhen()
);
if (numOfRowsAffected==1) return id;
else return -1;
public class Occurrence {
private Long id;
private Date when;
private String where;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getWhen() {
return when;
}
public void setWhen(Date when) {
this.when = when;
}
public String getWhere() {
return where;
}
public void setWhere(String where) {
this.where = where;
}
}
getWhen()如何在发生类中定义? –