开发者

How can I get the name of all tables in a JavaDB database?

开发者 https://www.devze.com 2022-12-29 16:13 出处:网络
How can I programmatically get the names of all tables in a JavaDB database? Is there any specific SQL-statement over JDBC I can use for this or any built in function in JDBC?

How can I programmatically get the names of all tables in a JavaDB database? Is there any specific SQL-statement over JDBC I can use for this or any built in function in JDBC?

I will use it for exporting the tables to XML, and would li开发者_运维问答ke to do it this way so I don't miss any tables from the database when exporting.


With an open Connection con, do

DatabaseMetaData meta = con.getMetaData();
  ResultSet res = meta.getTables(null, null, null, 
     new String[] {"TABLE"});
  System.out.println("List of tables: "); 
  while (res.next()) {
     System.out.println(
        "   "+res.getString("TABLE_CAT") 
       + ", "+res.getString("TABLE_SCHEM")
       + ", "+res.getString("TABLE_NAME")
       + ", "+res.getString("TABLE_TYPE")
       + ", "+res.getString("REMARKS")); 
  }
  res.close();

EDIT: You question is about tables see http://java.sun.com/j2se/1.5.0/docs/api/java/sql/DatabaseMetaData.html#getTables(java.lang.String, java.lang.String, java.lang.String, java.lang.String[])

0

精彩评论

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