[英]Jooq - Date column with time
In my oracle database, in a table, I have a Date column. 在我的oracle数据库的一个表中,我有一个Date列。 I fetch it using jooq, its a simple select query.
我使用jooq获取它,它是一个简单的选择查询。 The jooq fetches the column value, but without time.
jooq获取列值,但是没有时间。 Have I missed any configurations?
我错过任何配置了吗?
By default, jOOQ maps Oracle's DATE
column to java.sql.Date
and TIMESTAMP
to java.sql.Timestamp
. 默认情况下,jOOQ将Oracle的
DATE
列映射到java.sql.Date
并将TIMESTAMP
映射到java.sql.Timestamp
。
If you want to use Oracle's historic DATE
semantics (date-time with seconds precision), then you can have jOOQ generate java.sql.Timestamp
columns also for DATE
columns using the <dateAsTimestamp/>
code generation flag: 如果要使用Oracle的历史
DATE
语义(精确到秒的日期时间),则可以使用<dateAsTimestamp/>
代码生成标记让jOOQ为DATE
列生成java.sql.Timestamp
列:
<!-- Generate java.sql.Timestamp fields for DATE columns. This is
particularly useful for Oracle databases.
Defaults to false -->
<dateAsTimestamp>false</dateAsTimestamp>
Details here: http://www.jooq.org/doc/latest/manual/code-generation/codegen-advanced/ 此处的详细信息: http : //www.jooq.org/doc/latest/manual/code-generation/codegen-advanced/
This answer was also given on the jOOQ User Group jOOQ用户组也给出了这个答案
All the answers I could find for this issue on the web were more or less related to code generation, but I was working on a framework project and didn't want to couple my code to any specific databases. 我在网上可以找到的关于该问题的所有答案或多或少都与代码生成有关,但是我正在从事一个框架项目,并且不想将我的代码耦合到任何特定的数据库。
The problem I had was, JOOQ cut off the time part from the data of DATE
column when calling Record.getValue()
methods. 我遇到的问题是,在调用
Record.getValue()
方法时, Record.getValue()
从DATE
列的数据中切断了时间部分。
According to JOOQ's doc , I worked it around by getting the value of DATE
column from underlying ResultSet
instead of using Record.getValue()
. 根据JOOQ的文档 ,我通过从基础
ResultSet
DATE
列的ResultSet
而不是使用Record.getValue()
。
Sample code: 样例代码:
ResultQuery<Record> query;
Cursor<Record> cursor = query.fetchLazy(fetchSize);
cursor.fetchOne(new RecordMapper<Record, Map<String, Object>>() {
@Override
public Map<String, Object> map(final Record record) {
for (Field<?> field : record.fields()) {
record.getValue(field, converter);
if ("date".equals(field.getDataType().getTypeName())) {
resultSet resultSet = cursor.resultSet();
try {
Timestamp ts = resultSet.getTimestamp(field.getName());
} catch (SQLException e) {
// ......
}
}
}
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.