how to get table structre of a database in java?
Use DatabaseMetaData to get the table information.
You can use the getTablexxx()
and getColumnxx()
methods to get the table information.
Connection conn = DriverManager.getConnection(.....);
DatabaseMetaData dbmd = conn.getMetaData();
dbmd.getxxxx();
If you just care about being able to recreate the table on a different server, you can use SHOW TABLES
to get a list of tables, then SHOW CREATE TABLE foo
to get the CREATE TABLE
command. You might also look at the mysqldump program to see if it better suits your needs.
Joshua
One way is to use hibernate, reverse engineer and generate entity beans according to your existing database.
来源:https://stackoverflow.com/questions/4449437/how-to-get-table-structre-of-a-database-in-java