I'm trying to get value LEGAL_ENTITY_ID (Integer) from table for to use later.
public static int fetchingLegalEntityId() {
return DSL.using(connection).select(LEGAL_ENTITIES.LEGAL_ENTITY_ID)
.from(LEGAL_ENTITIES)
.where(LEGAL_ENTITIES.CODE.eq("someValue"))
.fetchOne();
}
but I have incompatible types. What I need to do?
CodePudding user response:
ResultQuery.fetchOne()
produces a Record
. There are many many ways to fetch data in jOOQ.
I could recommend various options, including:
fetchOptional().map(Record::value1).orElseThrow(...)
fetchOne(LEGAL_ENTITIES.LEGAL_ENTITY_ID)
DSLContext.fetchValue(select)
- And many more
There isn't a best way to do such a query. Just explore the jOOQ API (e.g. by using an IDE and auto-completing your fetch()
call to see what's available), and pick the style you prefer.