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

how to get database current time using jooq API

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

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

使用plain SQL is always an option, but why not use what's available in jOOQ already, e.g. 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.*;