1

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 like to do it this way so I don't miss any tables from the database when exporting.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Jonas
  • 121,568
  • 97
  • 310
  • 388

1 Answers1

6

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[])

stacker
  • 68,052
  • 28
  • 140
  • 210