JOOQ: Get table and columns with string?

别来无恙 提交于 2019-12-11 04:38:06

问题


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.


回答1:


Yes you can:

Using the code generator

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();

Using 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.




回答2:


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");


来源:https://stackoverflow.com/questions/46719087/jooq-get-table-and-columns-with-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!