简体   繁体   English

JOOQ 中的 Fetch 子句

[英]Fetch clause in JOOQ

I'm trying to get value LEGAL_ENTITY_ID (Integer) from table for to use later.我正在尝试从表中获取值 LEGAL_ENTITY_ID (Integer) 以供以后使用。

 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?我需要做什么?

ResultQuery.fetchOne() produces a Record . ResultQuery.fetchOne()产生一个Record There are many many ways to fetch data in jOOQ . 在 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 (eg by using an IDE and auto-completing your fetch() call to see what's available), and pick the style you prefer.只需探索 jOOQ API(例如,通过使用 IDE 并自动完成您的fetch()调用以查看可用的内容),然后选择您喜欢的样式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM