gpt4 book ai didi

java - JOOQ Java 8 Schema 是抽象的,无法实例化

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:38:52 25 4
gpt4 key购买 nike

在 JOOQ documentation它说我可以这样做:

try (Connection c = getConnection()) {
String sql = "select schema_name, is_default " +
"from information_schema.schemata " +
"order by schema_name";

DSL.using(c)
.fetch(sql)

// We can use lambda expressions to map jOOQ Records
.map(rs -> new Schema(
rs.getValue("SCHEMA_NAME", String.class),
rs.getValue("IS_DEFAULT", boolean.class)
))

// ... and then profit from the new Collection methods
.forEach(System.out::println);
}

但是,当我这样做时,我收到错误“org.jooq.Schema 是抽象的;无法实例化” - 如果您查看 documentation没错。

那么示例中的代码到底应该如何工作?

最佳答案

简短回答:他们没有使用 "org.jooq.Schema"在他们的示例中,而是一个静态内部类。


如果您向下滚动到 the page you linked 的底部,他们提供示例的 github 链接。您的示例是 SQL goodies一个。

如果你打开SQLGoodies.java您会注意到示例类顶部的静态内部类 Schema

static class Schema {
final String schemaName;
final boolean isDefault;

Schema(String schemaName, boolean isDefault) {
this.schemaName = schemaName;
this.isDefault = isDefault;
}

@Override
public String toString() {
return "Schema{" +
"schemaName='" + schemaName + '\'' +
", isDefault=" + isDefault +
'}';
}
}

然后向下滚动,您将找到使用内部类的示例:

 DSL.using(c)
.fetch(sql)
.map(r -> new Schema(
r.getValue("SCHEMA_NAME", String.class),
r.getValue("IS_DEFAULT", boolean.class)
))

关于java - JOOQ Java 8 Schema 是抽象的,无法实例化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36878605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com