gpt4 book ai didi

java - java.util.Calendar.MONTH 和 Oracle 数据库 MONTH 函数之间的差异

转载 作者:行者123 更新时间:2023-12-02 05:32:09 27 4
gpt4 key购买 nike

我想通过 JPA 从 Oracle 数据库中选择实体,方法如下:

Calendar cal = Calendar.getInstance();
cal.setTime(anOtherDate);

Query q = super.getEntityManager()
.createQuery("select t from MyTable as t
where extract(month from t.myDate) = :month")
.setParameter("month", cal.get(Calendar.MONTH));

但是 Java 和 Oracle 数据库的月份数不同...

有没有一种“更干净”的方法来做到这一点:cal.get(Calendar.MONTH)+1)

最佳答案

既然您无论如何都依赖于 native SQL,为什么不从数据库的 sysdate 中提取月份进行比较呢?

关于java - java.util.Calendar.MONTH 和 Oracle 数据库 MONTH 函数之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25421865/

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