The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.sql  [73 examples] > Tables  [6 examples]

e247. Listing All Table Names in a Database

    try {
        // Gets the database metadata
        DatabaseMetaData dbmd = connection.getMetaData();
    
        // Specify the type of object; in this case we want tables
        String[] types = {"TABLE"};
        ResultSet resultSet = dbmd.getTables(null, null, "%", types);
    
        // Get the table names
        while (resultSet.next()) {
            // Get the table name
            String tableName = resultSet.getString(3);
    
            // Get the table's catalog and schema names (if any)
            String tableCatalog = resultSet.getString(1);
            String tableSchema = resultSet.getString(2);
        }
    } catch (SQLException e) {
    }

 Related Examples
e245. Creating a Database Table
e246. Deleting a Database Table
e248. Creating a MySQL Table to Store Java Types
e249. Creating an Oracle Table to Store Java Types
e250. Creating a SQLServer Table to Store Java Types

See also: Batching    Connections    Database Meta Data    Deleting Data    Drivers    Importing and Exporting    Inserting and Updating Data    Oracle OBJECTs    Oracle VARRAYs    Procedures and Functions    Retrieving Data    Scrollable Result Sets    Updatable Result Sets   


© 2002 Addison-Wesley.