h2调用mysql数据,访问H2数据库架构

Im currently accessing an embedded H2 database in java using jOOQ to generate table classes etc. I can currently execute queries such as

create.select().from(TEST).fetch()

in my code, return results etc.

However I cant query the information schema. I can access it ok using the H2 console, and creating a view for a given information_schema table works fine. My question is how should I be accessing the information_schema eg to perform a query such as

SELECT * FROM INFORMATION_SCHEMA.TABLES

from within my java code? Do I have to create a view, can the schema be accessed through jooq-meta or some other means, or do I need to add something to the property file used by jooq-codegen (information_schema isn't created in the generated tables classes)? Or something else?

Edit:

This is my first foray into using jooq and am coming from a MySQL background. What I'm effectively trying to achieve is to be able to run some unit tests to ensure DB related code works. So I want to access the database's metadata (schema) and return something without having to know if any user created tables exist.

解决方案

You can generate classes for the INFORMATION_SCHEMA just as any other schema. In fact, jOOQ-meta contains some of those classes required for reverse-engineering your database schema.

The manual's section about advanced code generation properties mentions how you can configure the code generator to load several "input schemata":

...

[ ... ... ]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值