Reputation: 2912
In my oracle database, in a table, I have a Date column. I fetch it using jooq, its a simple select query. The jooq fetches the column value, but without time. Have I missed any configurations?
Upvotes: 2
Views: 4484
Reputation: 11
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.
According to JOOQ's doc, I worked it around by getting the value of DATE
column from underlying ResultSet
instead of using 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) {
// ......
}
}
}
}
);
Upvotes: 1
Reputation: 220762
By default, jOOQ maps Oracle's DATE
column to java.sql.Date
and TIMESTAMP
to 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:
<!-- 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/
This answer was also given on the jOOQ User Group
Upvotes: 2