在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)
))