如何使用jooq API获取数据库当前时间

时间:2017-08-05 01:27:23

标签: java sql jooq

如何使用jooq API获取当前数据库时间。以下是正确的方法吗?

Record result = DSL.using(configuration).fetchOne("Select CURRENT_TIMESTAMP() as NOW");
Timestamp now = result.get("NOW", Timestamp.class);

1 个答案:

答案 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.*;