如何使用jooq获取数据库当前时间API
问题描述:
如何使用jooq API获取当前数据库时间。下面是正确的方法?如何使用jooq获取数据库当前时间API
Record result = DSL.using(configuration).fetchOne("Select CURRENT_TIMESTAMP() as NOW");
Timestamp now = result.get("NOW", Timestamp.class);
答
使用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.*;