Get table information from DatabaseMetaData : DatabaseMetadata « Database « Java Tutorial

Java Tutorial
1. Language
2. Data Type
3. Operators
4. Statement Control
5. Class Definition
6. Development
7. Reflection
8. Regular Expressions
9. Collections
10. Thread
11. File
12. Generics
13. I18N
14. Swing
15. Swing Event
16. 2D Graphics
17. SWT
18. SWT 2D Graphics
19. Network
20. Database
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web Services SOA
27. EJB3
28. Spring
29. PDF
30. Email
31. J2ME
32. J2EE Application
33. XML
34. Design Pattern
35. Log
36. Security
37. Apache Common
38. Ant
39. JUnit
Java
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Tutorial » Database » DatabaseMetadata 
20. 30. 12. Get table information from DatabaseMetaData
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;

public class Main {
  public static void main(String[] argsthrows Exception {
    Connection conn = getConnection();

    DatabaseMetaData mtdt = conn.getMetaData();

    ResultSet rs = mtdt.getTables(conn.getCatalog()"%""%"null);
    
    ResultSetMetaData rsmd = rs.getMetaData();
    int numCols = rsmd.getColumnCount();
    for (int i = 1; i <= numCols; i++) {
      if (i > 1)
        System.out.print(", ");
      System.out.print(rsmd.getColumnLabel(i));
    }
    System.out.println("");
    while (rs.next()) {
      for (int i = 1; i <= numCols; i++) {
        if (i > 1)
          System.out.print(", ");
        System.out.print(rs.getString(i));
      }
      System.out.println("");
    }
    conn.close();
  }

  private static Connection getConnection() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");
    String url = "jdbc:hsqldb:mem:data/tutorial";

    return DriverManager.getConnection(url, "sa""");
  }
}
TABLE_CAT, TABLE_SCHEM, TABLE_NAME, TABLE_TYPE, REMARKS, TYPE_CAT, TYPE_SCHEM, TYPE_NAME, SELF_REFERENCING_COL_NAME, REF_GENERATION, HSQLDB_TYPE, READ_ONLY
null, INFORMATION_SCHEMA, SYSTEM_ALIASES, SYSTEM TABLE, the aliases defined within this database, null, null, null, null, null, MEMORY, true
null, INFORMATION_SCHEMA, SYSTEM_ALLTYPEINFO, SYSTEM TABLE, a description of all non user-defined data types known to this database and the level of support for them in various capacities, null, null, null, null, null, MEMORY, true
null, INFORMATION_SCHEMA, SYSTEM_AUTHORIZATIONS, SYSTEM TABLE, one row for each user and one row for each role , null, null, null, null, null, MEMORY, true
null, INFORMATION_SCHEMA, SYSTEM_BESTROWIDENTIFIER, SYSTEM TABLE, for each accessible table defined within this database, the optimal set of visible columns that uniquely identifies a row, null, null, null, null, null, MEMORY, true
null, INFORMATION_SCHEMA, SYSTEM_CACHEINFO, SYSTEM TABLE, the current state of the system row caching mechanism, null, null, null, null, null, MEMORY, true
null, INFORMATION_SCHEMA, SYSTEM_CATALOGS, SYSTEM TABLE, the accessible catalogs defined within this database, null, null, null, null, null, MEMORY, true
null, INFORMATION_SCHEMA, SYSTEM_CHECK_COLUMN_USAGE, SYSTEM TABLE, one row for each column identified by a  contained in the  of a check constraint, domain constraint, or assertion., null, null, null, null, null, MEMORY, true
null, INFORMATION_SCHEMA, SYSTEM_CHECK_CONSTRAINTS, SYSTEM TABLE, one row for each domain constraint, table check constraint, and assertion., null, null, null, null, null, MEMORY, true
null, INFORMATION_SCHEMA, SYSTEM_CHECK_ROUTINE_USAGE, SYSTEM TABLE, one row for each SQL-invoked routine identified as the subject routine of either a , a , a  , or a   contained in an , a , or a ., null, null, null, null, null, MEMORY, true
null, INFORMATION_SCHEMA, SYSTEM_CHECK_TABLE_USAGE, SYSTEM TABLE, one row for each table identified by a 
simply contained in a
contained in the of a check constraint, domain constraint, or assertion., null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_CLASSPRIVILEGES, SYSTEM TABLE, the visible user level access permissions for each Java class providing implementation for each accessible callable procedure, SQL function, trigger body and UDT method defined within this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_COLLATIONS, SYSTEM TABLE, one row for each character collation descriptor., null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_COLUMNPRIVILEGES, SYSTEM TABLE, the visible user level access permissions of each visible column of each accessible table defined within this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_COLUMNS, SYSTEM TABLE, the visible columns of each accessible table defined within this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_CROSSREFERENCE, SYSTEM TABLE, a description of how the accessible tables defined within this database import visible columns to enforce referential integrity, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_INDEXINFO, SYSTEM TABLE, information about the indicies of each accessible table defined within this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_PRIMARYKEYS, SYSTEM TABLE, the visible columns of the primary key of each accessible table defined within this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_PROCEDURECOLUMNS, SYSTEM TABLE, a description of the return type, parameters and result columns of each accessible callable procedure, SQL function, trigger body and UDT method defined within this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_PROCEDURES, SYSTEM TABLE, the procedures, SQL functions, trigger body routines and UDT methods defined within the database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_PROPERTIES, SYSTEM TABLE, the static and dynamic system properties and operating parameters of this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_ROLE_AUTHORIZATION_DESCRIPTORS, SYSTEM TABLE, one row for each role granted directly to a grantee, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_SCHEMAS, SYSTEM TABLE, the accessible schemas defined within this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_SCHEMATA, SYSTEM TABLE, one row for each schema., null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_SEQUENCES, SYSTEM TABLE, one row for each external sequence generator, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_SESSIONINFO, SYSTEM TABLE, information about the current database session, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_SESSIONS, SYSTEM TABLE, the visible sessions open in this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_SUPERTABLES, SYSTEM TABLE, the table hierarchies defined in this database. Only the immediate super type/sub type relationship is modeled, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_SUPERTYPES, SYSTEM TABLE, the user-defined type (UDT) hierarchies defined in this database. Only the immediate super type/sub type relationship is modeled, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_TABLEPRIVILEGES, SYSTEM TABLE, the visible user level access permissions for each accessible table defined within this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_TABLES, SYSTEM TABLE, the accessible tables defined within this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_TABLETYPES, SYSTEM TABLE, the types of tables that can be created/found within this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_TABLE_CONSTRAINTS, SYSTEM TABLE, one row for each table constraint associated with a table, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_TEXTTABLES, SYSTEM TABLE, the data source descriptors of the accessible TEXT TABLE objects defined within this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_TRIGGERCOLUMNS, SYSTEM TABLE, the column usage of visible triggers defined within this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_TRIGGERS, SYSTEM TABLE, the visible triggers defined within this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_TYPEINFO, SYSTEM TABLE, a description of predefined table column data types known to this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_UDTATTRIBUTES, SYSTEM TABLE, a description of the attributes of the user-defined types (UDTs) that are available in this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_UDTS, SYSTEM TABLE, the user-defined types that are available within this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_USAGE_PRIVILEGES, SYSTEM TABLE, one row for each usage privilege descriptor., null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_USERS, SYSTEM TABLE, users defined within this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_VERSIONCOLUMNS, SYSTEM TABLE, the visible columns of the accessible tables that are automatically updated when any value in a row is updated, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_VIEWS, SYSTEM TABLE, the view descriptors of the accessible views defined within this database, null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_VIEW_COLUMN_USAGE, SYSTEM TABLE, one row for each column of a table that is explicitly or implicitly referenced in the of the view being described., null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_VIEW_ROUTINE_USAGE, SYSTEM TABLE, one row for each SQL-invoked routine identified as the subject routine of either a , a , a , or a contained in a , null, null, null, null, null, MEMORY, true null, INFORMATION_SCHEMA, SYSTEM_VIEW_TABLE_USAGE, SYSTEM TABLE, one row for each table identified by a
simply contained in a
that is contained in the of a view, null, null, null, null, null, MEMORY, true
20. 30. DatabaseMetadata
20. 30. 1. Database Metadata
20. 30. 2. Get Table Names from a Database
20. 30. 3. Get View Names from a Database
20. 30. 4. Get Table and View Names from a Database
20. 30. 5. DatabaseMetaData Methods for Database Information
20. 30. 6. Get Database information from DatabaseMetaData
20. 30. 7. DatabaseMetaData Methods for Information on the Database's Supported Features
20. 30. 8. DatabaseMetaData Methods for Information on the Database's Limitations
20. 30. 9. Display Database Limitation for your connection
20. 30. 10. DatabaseMetaData Methods for Information on the Database's Contents
20. 30. 11. Display Database contents for current connection
20. 30. 12. Get table information from DatabaseMetaData
20. 30. 13. Get procedure information from DatabaseMetaData
20. 30. 14. Listing All Non-SQL92 Keywords Used by a Database
20. 30. 15. Listing the String Functions Supported by a Database: retrieves a list of string functions that a database supports.
20. 30. 16. Listing the Numeric Functions Supported by a Database
20. 30. 17. Listing the System Functions Supported by a Database
20. 30. 18. Listing the Time and Date Functions Supported by a Database
20. 30. 19. Getting the Maximum Table Name Length allowed in a Database
20. 30. 20. Listing Available SQL data Types Used by a Database
20. 30. 21. Get system functions supported by database
20. 30. 22. Get the max concurrent connection to a database
20. 30. 23. Get database maximum table name length
20. 30. 24. Get numeric functions supported by database
20. 30. 25. If database support batch update
20. 30. 26. Get data types supported by database
20. 30. 27. Get date time functions supported by database
20. 30. 28. Detect if a table exists
20. 30. 29. Get string functions supported by database
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.