【问题标题】:the jooq according to sqlite datebase to generate java code failedjooq根据sqlite数据库生成java代码失败
【发布时间】:2022-07-20 19:58:10
【问题描述】:

我用jooq 3.16.5生成java代码,运行代码时,终端告诉我成功,但是代码没有生成,我不知道为什么,所以我把代码复制到这里希望有人帮助我

1.这是build.gradle

    buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        gradlePluginPortal()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url 'https://maven.aliyun.com/repository/public/'}
        google()
    }
    dependencies {

        classpath "org.jooq:jooq-codegen:3.16.5"
        classpath 'org.postgresql:postgresql:42.2.14'
        classpath 'org.xerial:sqlite-jdbc:3.30.1'
        classpath 'org.codehaus.groovy:groovy-all:3.0.11'
    }
}

plugins {
    id "org.flywaydb.flyway" version "8.5.13"
}

dependencies {
    implementation project(":core")
    api "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
    api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
    api "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-desktop"
    api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
    api "com.badlogicgames.gdx-controllers:gdx-controllers-desktop:$gdxControllersVersion"
    api "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"

    //flyway
    implementation group: 'org.flywaydb', name: 'flyway-core', version: '8.5.13'
    //jooq
    implementation group: 'org.jooq', name: 'jooq', version: '3.16.5'
    implementation group: 'org.jooq', name: 'jooq-meta', version: '3.16.5'
    implementation group: 'org.jooq', name: 'jooq-codegen', version: '3.16.5'
    implementation group: 'org.jooq', name: 'jooq-meta-extensions', version: '3.16.5'
    //groovy
    implementation 'org.codehaus.groovy:groovy-all:3.0.11'
    //sqlitejdbc
    implementation 'sqlitejdbc:sqlitejdbc:0.5.6'
    //postgresql
    implementation 'org.postgresql:postgresql:42.2.14'
}

2.这是生成pojo类和其他文件的java代码

import org.jooq.codegen.GenerationTool;
import org.jooq.meta.jaxb.Configuration;
import org.jooq.meta.jaxb.Database;
import org.jooq.meta.jaxb.Generate;
import org.jooq.meta.jaxb.Generator;
import org.jooq.meta.jaxb.Jdbc;
import org.jooq.meta.jaxb.Property;
import org.jooq.meta.jaxb.Target;

public class JooqConfig {
    public static void main(String[] args) {

        Configuration configuration = new Configuration()

                // Configure the database connection here
                .withJdbc(new Jdbc()
                        .withDriver("org.sqlite.JDBC")
                        .withUrl("jdbc:sqlite:/home/myusername/sql/changdao.sqlite")
                )
                .withGenerator(new Generator()
                        .withDatabase(new Database()
                                .withName("org.jooq.meta.sqlite.SQLiteDatabase")
                                .withIncludes(".*")
                                .withExcludes("" +
                                        "UNUSED_TABLE                # This table (unqualified name) should not be generated" +
                                        "| PREFIX_.*                   # Objects with a given prefix should not be generated" +
                                        "| SECRET_SCHEMA\\.SECRET_TABLE # This table (qualified name) should not be generated" +
                                        "| SECRET_ROUTINE              # This routine (unqualified name) ..." +
                                        "")
                                .withInputSchema("public")
                        )

                        // Generation flags: See advanced configuration properties
                        .withGenerate(new Generate()
                                .withPojos(true)
                                .withComments(true)
                                .withCommentsOnCatalogs(true)
                                .withRelations(true)
                                .withImmutablePojos(false) // if true, cannot use 'into()' method
                                .withInterfaces(true)
                                .withDaos(true))
                        .withTarget(new Target()
                                .withPackageName("com.changdao.game.db")
                                .withDirectory("desktop/src")
                        )
                );
        try {
            GenerationTool.generate(configuration);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

这是我的数据库

还有sql,顺便说一下,我用flyway建表

create table product(
     id INTEGER primary key,
     create_time TEXT
);

我使用 jdk 11,但我不知道它是否重要

我希望有人能帮助我,非常感谢你

【问题讨论】:

    标签: java sqlite jooq


    【解决方案1】:

    您已指定:

    withInputSchema("public")
    

    但是 SQLite 不支持模式。所以它没有public 模式(例如PostgreSQL)。只需删除它,它应该可以工作。

    请注意,在您的代码生成输出中应该有关于此的 INFO 消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 2021-01-19
      • 2016-10-28
      • 2015-11-20
      • 1970-01-01
      • 2022-01-12
      相关资源
      最近更新 更多