我是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()如何在發生類中定義? –