2017-08-05 39 views
1

如何使用jooq API獲取當前數據庫時間。下面是正確的方法?如何使用jooq獲取數據庫當前時間API

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

回答

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.*; 
相關問題