Are there any Java libraries that allow me to generate DDL from Java code using a typesafe builder pattern, or similar?

Something along the lines of:

String sql = DDLGenerator.createTable("MY_TABLE")
                         .withPrimaryKey("my_id").ofNumberType().withPrecision(2, 2)

I'm not looking for an ORM solution such as Hibernate nor a database migration solution such as Liquibase or Flyway, nor a tool that works with an existing schema.

1 Answer 1



jOOQ provides a DSL for creating tables:

Connection conn = ... //code that creates a DB connection
DSLContext create = DSL.using(conn, SQLDialect.ORACLE);
    .column("my_id", SQLDataType.DECIMAL.precision(2, 2))
    .column("name", SQLDataType.VARCHAR.length(30).nullable(false))
    .withPrimaryKey("my_id").ofNumberType().withPrecision(2, 2)
    .on("MY_TABLE", "name")

See Wikipedia.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.