【问题标题】:can't generate java from command line: org.jooq.exception.DetachedException: Cannot execute query. No Connection configured无法从命令行生成 java:org.jooq.exception.DetachedException:无法执行查询。未配置连接
【发布时间】:2015-01-31 21:43:07
【问题描述】:

我试图从我的数据库中生成 JOOQ Java 代码。

当我执行时

java -cp "bla.xml;jooq-3.5.0.jar;jooq-meta-3.5.0.jar;jooq-codegen-3.5.0.jar;jtds.jar" org.jooq.util.GenerationTool bla.xml

我明白了:

org.jooq.exception.DetachedException: Cannot execute query. No Connection configured
        at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:303)

我不知道为什么它不生成 java 代码。 创业公司说:

Dez 03, 2014 11:43:33 AM org.jooq.tools.JooqLogger info
Information: Initialising properties  : bla.xml
Dez 03, 2014 11:43:33 AM org.jooq.tools.JooqLogger warn
Warnung: DEPRECATED               : The configuration property /configuration/generator/database/dateAsTimestamp is deprecated as it is superseded by custom bindings and converters. It will thus be removed in the future.
Dez 03, 2014 11:43:33 AM org.jooq.tools.JooqLogger info
Information: License parameters
Dez 03, 2014 11:43:33 AM org.jooq.tools.JooqLogger info
Information: ----------------------------------------------------------
Dez 03, 2014 11:43:33 AM org.jooq.tools.JooqLogger info
Information:   Thank you for using jOOQ and jOOQ's code generator
Dez 03, 2014 11:43:33 AM org.jooq.tools.JooqLogger info
Information:
Dez 03, 2014 11:43:33 AM org.jooq.tools.JooqLogger info
Information: Database parameters
Dez 03, 2014 11:43:33 AM org.jooq.tools.JooqLogger info
Information: ----------------------------------------------------------
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   dialect                : SQLSERVER
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   URL                    :
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   target dir             : C:/Users/x/Downloads/jOOQ-3.5.0/jOOQ-lib/src
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   target package         : de.xy.model.database
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   includes               : [.*]
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   excludes               : []
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   includeExcludeColumns  : false
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information: ----------------------------------------------------------
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information: DefaultGenerator parameters
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information: ----------------------------------------------------------
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   strategy               : class org.jooq.util.DefaultGeneratorStrategy
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   deprecated             : true
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   generated annotation   : true
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   JPA annotations        : false
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   validation annotations : false
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   instance fields        : true
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   records                : true
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   pojos                  : false
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   immutable pojos        : false
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   interfaces             : false
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   daos                   : false
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   relations              : true
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   global references      : true
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information: ----------------------------------------------------------
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information: Generation remarks
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information: ----------------------------------------------------------
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:   none
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information: ----------------------------------------------------------
Dez 03, 2014 11:43:34 AM org.jooq.tools.JooqLogger info
Information:

bla.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration>
  <!-- Configure the database connection here -->
  <jdbc>
    <driver>net.sourceforge.jtds.jdbc.Driver</driver>
    <url>jdbc:sqlserver://localhost:1433;databaseName=x</url>


    <!-- You can also pass user/password and other JDBC properties in the optional properties tag: -->
     <properties>
      <property><key>user</key><value>x</value></property>
      <property><key>password</key><value>x</value></property>
    </properties>
  </jdbc>

  <generator>
    <database>
      <!-- The database dialect from jooq-meta. Available dialects are
           named org.util.[database].[database]Database.

           Natively supported values are:

               org.jooq.util.ase.ASEDatabase
               org.jooq.util.cubrid.CUBRIDDatabase
               org.jooq.util.db2.DB2Database
               org.jooq.util.derby.DerbyDatabase
               org.jooq.util.firebird.FirebirdDatabase
               org.jooq.util.h2.H2Database
               org.jooq.util.hsqldb.HSQLDBDatabase
               org.jooq.util.informix.InformixDatabase
               org.jooq.util.ingres.IngresDatabase
               org.jooq.util.mariadb.MariaDBDatabase
               org.jooq.util.mysql.MySQLDatabase
               org.jooq.util.oracle.OracleDatabase
               org.jooq.util.postgres.PostgresDatabase
               org.jooq.util.sqlite.SQLiteDatabaes
               org.jooq.util.sqlserver.SQLServerDatabase
               org.jooq.util.sybase.SybaseDatabase

           This value can be used to reverse-engineer generic JDBC DatabaseMetaData (e.g. for MS Access)

               org.jooq.util.jdbc.JDBCDatabase

           This value can be used to reverse-engineer standard jOOQ-meta XML formats

               org.jooq.util.xml.XMLDatabase

           You can also provide your own org.jooq.util.Database implementation
           here, if your database is currently not supported -->
      <name>org.jooq.util.sqlserver.SQLServerDatabase</name>

      <!-- All elements that are generated from your schema (A Java regular expression.
           Use the pipe to separate several expressions) Watch out for
           case-sensitivity. Depending on your database, this might be
           important!

           You can create case-insensitive regular expressions using this syntax: (?i:expr)

           Whitespace is ignored and comments are possible.
           -->
      <includes>.*</includes>

      <!-- All elements that are excluded from your schema (A Java regular expression.
           Use the pipe to separate several expressions). Excludes match before
           includes -->
      <excludes>
  <!--         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) ...
         -->
      </excludes>

      <!-- The schema that is used locally as a source for meta information.
           This could be your development schema or the production schema, etc
           This cannot be combined with the schemata element.

           If left empty, jOOQ will generate all available schemata. See the
           manual's next section to learn how to generate several schemata -->
      <inputSchema>dbo</inputSchema>
    </database>

    <generate>
      <!-- Generation flags: See advanced configuration properties -->
    </generate>

    <target>
      <!-- The destination package of your generated classes (within the
           destination directory)

           jOOQ may append the schema name to this package if generating multiple schemas,
           e.g. org.jooq.your.packagename.schema1
                org.jooq.your.packagename.schema2 -->
      <packageName>de.x.model.database</packageName>

      <!-- The destination directory of your generated classes -->
      <directory>C:/Users/athom/Downloads/jOOQ-3.5.0/jOOQ-lib/src</directory>
    </target>
  </generator>
</configuration>

【问题讨论】:

  • 你能显示你正在使用的代码生成配置(bla.xml)吗?您是否正确定义了 this example 中的 jdbc 部分?
  • 更新了问题。我用了那个例子。
  • 您的命令行调用对我来说看起来不错。你遇到的异常是第一个异常吗?它的完整堆栈跟踪是什么?另外,您确定您的连接字符串正确吗?如果您使用的是 jtds(而不是商业 SQL Server JDBC 驱动程序),I suspect you should have something with jtds in it...?
  • jtds url 是问题所在。您可以将您的评论放入答案中。

标签: java code-generation jooq


【解决方案1】:

您使用 jTDS 作为驱动程序实现,但使用的是 SQL Server JDBC 驱动程序 URL:

jdbc:sqlserver://localhost:1433;databaseName=x

jTDS 连接 URL 格式略有不同。本质上,您缺少 jtds: 前缀,并且数据库名称以 / 为前缀:

jdbc:jtds:sqlserver://localhost:1433/x

更多信息可以在这里看到:

【讨论】:

    猜你喜欢
    • 2019-12-11
    • 1970-01-01
    • 2011-09-15
    • 1970-01-01
    • 2016-01-21
    • 2019-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多