desc command through code
开发者_StackOverflow社区Can we get the table description through java code that we get by typing desc in Toad?
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 want to just get column names,types, precision etc you can use ResultSetMetaData. Here is an example.
If you want to go beyond this and find out all the constraints, indexes etc defined on the table you can query the corresponding data dictionary views.
select dbms_metadata.get_ddl('TABLE','YOUR_TABLE_NAME')
from dual;
It will show you column names,types as well as additional components for creating this table,such as TABLESPACE...;
DBMS_METADATA package or
Select * from all_tab_columns where owner=user and table_name='table_name' order by column_id
精彩评论