Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JOOQ dynamic table name

Tags:

mysql

jooq

Say for example my function accepts a parameter called 'entityType', and according to that it queries the table entityType_other_stuff.

Is this possible to implement in JOOQ on runtime?

like image 627
aclowkay Avatar asked Mar 11 '26 06:03

aclowkay


1 Answers

The correct way to create dynamic org.jooq.Table objects by name is to use DSL.table(Name) as in:

String parameter = "entityType";
Table<?> table = table(name(parameter + "_other_stuff"));

If you use the standard Settings.renderNameStyle QUOTED, then the identifier will be quoted and escaped, and thus SQL-injection safe.

For more information, see the manual: https://www.jooq.org/doc/latest/manual/sql-building/names

like image 69
Lukas Eder Avatar answered Mar 14 '26 07:03

Lukas Eder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!