gpt4 book ai didi

java - 如何使用hql在MySql中设置日期时间字段

转载 作者:可可西里 更新时间:2023-11-01 08:36:25 25 4
gpt4 key购买 nike

我在 MySql 数据库中以 YYYY-mm-dd hh:mm:ss 格式插入日期时遇到问题。数据库中的文件是日期时间类型。

我试过了:

Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.set(Calendar.MINUTE, startMinute);
calendar.set(Calendar.SECOND,01);
Date startTime = calendar.getTime();

String hqlUpdate = "update challenge set start_time = :startTime where challenge_id = :id";
sessionFactory.getCurrentSession().createSQLQuery(hqlUpdate)
.setDate("startTime", startTime)
.setInteger("id", id).executeUpdate();

最佳答案

尝试使用以下内容。

.setTimestamp("startTime", startTime);

关于java - 如何使用hql在MySql中设置日期时间字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10493273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com