how to get table structre of a database in java?
how to get table structre of a database in java? [closed]
Asked Answered
You need to add context and additional detail to this question. As-is, it's not possible to answer. –
Fennelly
Actually i want to take backup of sql database. please help in this regard.i-e what will be algorithm,or steps involve to do so? –
Sjambok
You could use SHOW TABLES, then each result will have a line containing table name. Use SHOW CREATE TABLE <table_name> to get table creation code. –
Leaf
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();
And there is ResultSetMetaData: download.oracle.com/javase/6/docs/api/java/sql/… –
Slavin
+1. This is the official interface, but it is a terrible one. It returns ResultSets that you have to parse. They could have thrown in some proper interfaces for these data structures in one of the JDBC revs. –
Glazed
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.
© 2022 - 2024 — McMap. All rights reserved.