开发者

how to get table structre of a database in java? [closed]

开发者 https://www.devze.com 2023-01-31 05:22 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

how to get table structre of a dat开发者_如何学运维abase 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号