How do I check what table types exist in a database?
Created May 3, 2012
Lennart Jorelid Use the getTableTypes method of interface
java.sql.DatabaseMetaData to probe the database for table types.
The exact usage is described in the code below.
public static void main(String[] args) throws Exception { // Load the database driver - in this case, we // use the Jdbc/Odbc bridge driver. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Open a connection to the database Connection conn = DriverManager.getConnection("[jdbcURL]", "[login]", "[passwd]"); // Get DatabaseMetaData DatabaseMetaData dbmd = conn.getMetaData(); // Get all table types. ResultSet rs = dbmd.getTableTypes(); // Printout table data while(rs.next()) { // Printout System.out.println("Type: " + rs.getString(1)); } // Close database resources rs.close(); conn.close(); } |