Hello I'm using JOOQ with Spring Boot and was wondering if there was a way to obtain a table and its columns with a string of their name? For example:
I want to be able to get a table by doing something like:
someObject.getTable("user")
Then using the result of that get method I also want to obtain all of that table's columns and be able to compare the column names to other strings. In other words if there is a way to get a table, can I also get the table's column names from that same object?
I would really appreciate any help with this.
Yes you can:
When you generate your schema, all this information is available to you from generated code. Just go to your schema and look for the table (case-sensitive!):
Table<?> table = PUBLIC.getTable("user");
And then:
Field<?>[] fields = table.fields();
org.jooq.Meta
If you don't have generated meta data, you can still look up things from your JDBC connection using DSLContext.meta()
, from where you can navigate your schemas / tables / etc.
Yes. As correctly stated above, only one addition to further clarify the upcoming users, PUBLIC is your DefaultSchema, if you have with you, meta generated code. So,
Table<?> table = new DefaultSchema().getTable("user");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With