ahyea ahyea - 2 months ago 10
Java Question

JOOQ - How to get the tbl_name.col_name of a TableField?

How to get the table + column qualifier name from the TableField.

I have tried the following methods

USER.ID.toString(); // "db.user.id"
USER.ID.getName(); // "id"

Answer Source

As you've noticed, the TableField.toString() method renders the fully qualified column. You have two options:

Do it yourself:

String sql = USER.getName() + "." + USER.ID.getName();

Use a Configuration that is configured to omit the schema name:

Settings settings = new Settings();
settings.setRenderSchema(false);                    // Omit schema rendering
settings.setRenderNameStyle(RenderNameStyle.AS_IS); // Omit escaping names
DSLContext = DSL.using(SQLDialect.MYSQL, settings);
String sql = ctx.ender(USER.ID);