All versions: 3.11 | 3.10 | 3.9 | Development versions: 3.12

This optional top level configuration element allows for configuring a JDBC connection. By default, the jOOQ code generator requires an active JDBC connection to reverse engineer your database schema. For example, if you want to connect to a MySQL database, write this:

XML configuration (standalone and Maven)

<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.11.0.xsd">
  <jdbc>
    <driver>com.mysql.jdbc.Driver</driver>
    <url>jdbc:mysql://localhost/testdb</url>

    <!-- 
    <username/> is a valid synonym for <user/>
    -->

    <user>root</user>
    <password>secret</password>
  </jdbc>
  ...
</configuration>

Programmatic configuration

configuration
  .withJdbc(new Jdbc()
    .withDriver("com.mysql.jdbc.Driver")
    .withUrl("jdbc:mysql://localhost/testdb")
    .withUser("root")
    .withPassword("secret"));

Note that when using the programmatic configuration API through the GenerationTool, you can also pass a pre-existing JDBC connection to the GenerationTool and leave this configuration element alone.

Gradle configuration

myConfigurationName(sourceSets.main) {
  jdbc {
    driver = 'com.mysql.jdbc.Driver'
    url = 'jdbc:mysql://localhost/testdb'
    user = 'root'
    password = 'secret'
  }
}

Optional JDBC properties

JDBC drivers allow for passing java.util.Properties to the JDBC driver when creating a connection. This is also supported in the code generator configuration with a list of key/value pairs as follows:

XML configuration (standalone and Maven)

<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.11.0.xsd">
  <jdbc>
    <driver>com.mysql.jdbc.Driver</driver>
    <url>jdbc:mysql://localhost/testdb</url>
    <properties>
      <property>
        <key>user</key>
        <value>root</value>
      </property>
      <property>
        <key>password</key>
        <value>secret</value>
      </property>
    </properties>
  </jdbc>
  ...
</configuration>

Programmatic configuration

configuration
  .withJdbc(new Jdbc()
    .withDriver("com.mysql.jdbc.Driver")
    .withUrl("jdbc:mysql://localhost/testdb")
    .withProperties(
      new Property().withKey("user").withValue("root"),
      new Property().withKey("password").withValue("secret")));

Gradle configuration

myConfigurationName(sourceSets.main) {
  jdbc {
    driver = 'com.mysql.jdbc.Driver'
    url = 'jdbc:mysql://localhost/testdb'
    properties {
      property {
        key = 'user'
        value = 'root'
      }
      property {
        key = 'password'
        value = 'secret'
      }
    }
  }
}

Using variables in Maven

Quite often, you'd like to keep passwords (or other elements) out of your configuration, or you'd like to repeat common values for different plugins, e.g. for both jOOQ and Flyway. In those cases, the programmatic configuration makes it easiest to quickly replace them, because those values are just ordinary Java local variables for that API. When you use the XML configuration with Maven, you can also very simply use Maven's property mechanism to achieve something like this:

<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.11.0.xsd">
  <jdbc>
    <driver>${db.driver}</driver>
    <url>${db.url}</url>
    <user>${db.user}</user>
    <password>${db.password}</password>
  </jdbc>
  ...
</configuration>

When the JDBC configuration is optional

There are some exceptions, where the JDBC connection does not need to be configured, for instance when using the JPADatabase (to reverse engineer JPA annotated entities) or when using the XMLDatabase (to reverse engineer an XML file). Please refer to the respective sections for more details.

The jOOQ Logo