Is there a way, using JDBI, to get information about what tables are contained in the schema?
I have two databases A and B, and I need to be able to
- query A and retrieve a list of tables from it;
- query B and check that those same tables exist and have the same definitions (I don't care about the data in the tables).
I can do this using mysqldump
from the command line: retrieve the CREATE TABLE
statements from each database and compare them. But now I need to do it as part of a test, in a Dropwizard/JDBI context.
The documentation is a bit sparse, but I can't find anything suitable to enable me to do it. I might be able to
handle.execute("show tables");
etc., but that seems a bit low level, and I was hoping there would be a better way.
Or do I need to resort to JDBC?
JDBC has several database provider independent mechanisms.
From the connection you can get DatabaseMetaData, and do a query-by-expression on it (null = any).
Beware: names may be case-sensitive here and such.