select now();命令查看MySql时间(包括时分秒)
select current_date();命令查看MySql时间(不包括时分秒)
在代码中,创建时间、修改时间字段的jdbc语句也可以使用now()或current_date()
public void addGoddess(Goddess goddess) throws SQLException {
Connection connection = DBUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(
"insert into imooc_goddess(user_name, sex, age, birthday, email, mobile, " +
"create_user, create_date, update_user, update_date, isdel) " +
"values(?,?,?,?,?,?,?, now(), ?, current_date(), ?)");
preparedStatement.setString(1, goddess.getUser_name());
preparedStatement.setInt(2, goddess.getSex());
preparedStatement.setInt(3, goddess.getAge());
preparedStatement.setDate(4, new Date(goddess.getBirthday().getTime()));
preparedStatement.setString(5, goddess.getEmail());
preparedStatement.setString(6, goddess.getMobile());
preparedStatement.setString(7, goddess.getCreate_user());
preparedStatement.setString(8, goddess.getUpdate_user());
preparedStatement.setInt(9, goddess.getIsDel());
preparedStatement.execute();
}