如何使用jooq API获取当前数据库时间。以下是正确的方法吗?
Record result = DSL.using(configuration).fetchOne("Select CURRENT_TIMESTAMP() as NOW");
Timestamp now = result.get("NOW", Timestamp.class);
答案 0 :(得分:1)
使用plain SQL始终是一种选择,但为什么不使用jOOQ中可用的内容,例如: DSL.currentTimestamp()
Timestamp now = using(configuration)
.select(currentTimestamp())
.fetchOne(0, Timestamp.class);
甚至更简单:
Timestamp now = using(configuration).fetchValue(select(currentTimestamp());
与往常一样,这些jOOQ查询假设您使用以下静态导入:
import static org.jooq.impl.DSL.*;