开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜