DatabaseMetaData is an interface as part of JDBC API to get a comprehensive information on the Database. The implementation for this interface is provided by the JDBC vendors.

The methods defined in this interface are mainly used to estimate/identify the capabilities of a Database. For example, if a program is using two different Databases, it should consider only the construct which can be used as part of two different databases. Programmer can identify whether the construct is working or not with this interface. Here is a demo program to identify few parameters

DatabaseMetaDataDemo.java

import java.sql.*;

/**
* A demo class to explain DatabaseMetaData
* @author Santhosh Reddy Mandadi
* @since 25-Jun-2012
* @version 1.0
*/

public class DatabaseMetaDataDemo
{
public static void main(String args[]) throws Exception
{
String driverClass, jdbcURL, userName, password;

/*
//Reading the user defined system properties
driverClass = System.getProperty("driverClass");
jdbcURL = System.getProperty("jdbcURL");
userName = System.getProperty("userName");
password = System.getProperty("password");
*/
driverClass = "oracle.jdbc.driver.OracleDriver";
jdbcURL = "jdbc:oracle:@localhost:1521:xe";
userName = "scott";
password = "tiger";
Class.forName(driverClass);
Connection connection = DriverManager.getConnection(jdbcURL, userName, password);
DatabaseMetaData metaData = connection.getMetaData();
System.out.println("Connected to...."+metaData.getDatabaseProductName()+""+metaData.getDatabaseMajorVersion()+"."+metaData.getDatabaseMinorVersion());
System.out.println("Supports stored procedures:"+metaData.supportsStoredProcedures());
System.out.println("Maximum number of connections:"+metaData.getMaxConnections());
System.out.println("Number of bytes this Database allows in a single row:"+metaData.getMaxRowSize());
System.out.println("Maximum length that is allowed for schema name in this Database: "+metaData.getMaxSchemaNameLength());
System.out.println("Maximum length that is allowed for procedures names:"+metaData.getMaxProcedureNameLength());
System.out.println("Maximum number of columns that are allowed per table:"+metaData.getMaxColumnsInTable());
}
}
Below the list of methods that are available as part of the interface java.sql.DatabaseMetaData.

public abstract boolean allProceduresAreCallable() throws java.sql.SQLException;
public abstract boolean allTablesAreSelectable() throws java.sql.SQLException;
public abstract java.lang.String getURL() throws java.sql.SQLException;
public abstract java.lang.String getUserName() throws java.sql.SQLException;
public abstract boolean isReadOnly() throws java.sql.SQLException;
public abstract boolean nullsAreSortedHigh() throws java.sql.SQLException;
public abstract boolean nullsAreSortedLow() throws java.sql.SQLException;
public abstract boolean nullsAreSortedAtStart() throws java.sql.SQLException;
public abstract boolean nullsAreSortedAtEnd() throws java.sql.SQLException;
public abstract java.lang.String getDatabaseProductName() throws java.sql.SQLException;
public abstract java.lang.String getDatabaseProductVersion() throws java.sql.SQLException;
public abstract java.lang.String getDriverName() throws java.sql.SQLException;
public abstract java.lang.String getDriverVersion() throws java.sql.SQLException;
public abstract int getDriverMajorVersion();
public abstract int getDriverMinorVersion();
public abstract boolean usesLocalFiles() throws java.sql.SQLException;
public abstract boolean usesLocalFilePerTable() throws java.sql.SQLException;
public abstract boolean supportsMixedCaseIdentifiers() throws java.sql.SQLException;
public abstract boolean storesUpperCaseIdentifiers() throws java.sql.SQLException;
public abstract boolean storesLowerCaseIdentifiers() throws java.sql.SQLException;
public abstract boolean storesMixedCaseIdentifiers() throws java.sql.SQLException;
public abstract boolean supportsMixedCaseQuotedIdentifiers() throws java.sql.SQLException;
public abstract boolean storesUpperCaseQuotedIdentifiers() throws java.sql.SQLException;
public abstract boolean storesLowerCaseQuotedIdentifiers() throws java.sql.SQLException;
public abstract boolean storesMixedCaseQuotedIdentifiers() throws java.sql.SQLException;
public abstract java.lang.String getIdentifierQuoteString() throws java.sql.SQLException;
public abstract java.lang.String getSQLKeywords() throws java.sql.SQLException;
public abstract java.lang.String getNumericFunctions() throws java.sql.SQLException;
public abstract java.lang.String getStringFunctions() throws java.sql.SQLException;
public abstract java.lang.String getSystemFunctions() throws java.sql.SQLException;
public abstract java.lang.String getTimeDateFunctions() throws java.sql.SQLException;
public abstract java.lang.String getSearchStringEscape() throws java.sql.SQLException;
public abstract java.lang.String getExtraNameCharacters() throws java.sql.SQLException;
public abstract boolean supportsAlterTableWithAddColumn() throws java.sql.SQLException;
public abstract boolean supportsAlterTableWithDropColumn() throws java.sql.SQLException;
public abstract boolean supportsColumnAliasing() throws java.sql.SQLException;
public abstract boolean nullPlusNonNullIsNull() throws java.sql.SQLException;
public abstract boolean supportsConvert() throws java.sql.SQLException;
public abstract boolean supportsConvert(int, int) throws java.sql.SQLException;
public abstract boolean supportsTableCorrelationNames() throws java.sql.SQLException;
public abstract boolean supportsDifferentTableCorrelationNames() throws java.sql.SQLException;
public abstract boolean supportsExpressionsInOrderBy() throws java.sql.SQLException;
public abstract boolean supportsOrderByUnrelated() throws java.sql.SQLException;
public abstract boolean supportsGroupBy() throws java.sql.SQLException;
public abstract boolean supportsGroupByUnrelated() throws java.sql.SQLException;
public abstract boolean supportsGroupByBeyondSelect() throws java.sql.SQLException;
public abstract boolean supportsLikeEscapeClause() throws java.sql.SQLException;
public abstract boolean supportsMultipleResultSets() throws java.sql.SQLException;
public abstract boolean supportsMultipleTransactions() throws java.sql.SQLException;
public abstract boolean supportsNonNullableColumns() throws java.sql.SQLException;
public abstract boolean supportsMinimumSQLGrammar() throws java.sql.SQLException;
public abstract boolean supportsCoreSQLGrammar() throws java.sql.SQLException;
public abstract boolean supportsExtendedSQLGrammar() throws java.sql.SQLException;
public abstract boolean supportsANSI92EntryLevelSQL() throws java.sql.SQLException;
public abstract boolean supportsANSI92IntermediateSQL() throws java.sql.SQLException;
public abstract boolean supportsANSI92FullSQL() throws java.sql.SQLException;
public abstract boolean supportsIntegrityEnhancementFacility() throws java.sql.SQLException;
public abstract boolean supportsOuterJoins() throws java.sql.SQLException;
public abstract boolean supportsFullOuterJoins() throws java.sql.SQLException;
public abstract boolean supportsLimitedOuterJoins() throws java.sql.SQLException;
public abstract java.lang.String getSchemaTerm() throws java.sql.SQLException;
public abstract java.lang.String getProcedureTerm() throws java.sql.SQLException;
public abstract java.lang.String getCatalogTerm() throws java.sql.SQLException;
public abstract boolean isCatalogAtStart() throws java.sql.SQLException;
public abstract java.lang.String getCatalogSeparator() throws java.sql.SQLException;
public abstract boolean supportsSchemasInDataManipulation() throws java.sql.SQLException;
public abstract boolean supportsSchemasInProcedureCalls() throws java.sql.SQLException;
public abstract boolean supportsSchemasInTableDefinitions() throws java.sql.SQLException;
public abstract boolean supportsSchemasInIndexDefinitions() throws java.sql.SQLException;
public abstract boolean supportsSchemasInPrivilegeDefinitions() throws java.sql.SQLException;
public abstract boolean supportsCatalogsInDataManipulation() throws java.sql.SQLException;
public abstract boolean supportsCatalogsInProcedureCalls() throws java.sql.SQLException;
public abstract boolean supportsCatalogsInTableDefinitions() throws java.sql.SQLException;
public abstract boolean supportsCatalogsInIndexDefinitions() throws java.sql.SQLException;
public abstract boolean supportsCatalogsInPrivilegeDefinitions() throws java.sql.SQLException;
public abstract boolean supportsPositionedDelete() throws java.sql.SQLException;
public abstract boolean supportsPositionedUpdate() throws java.sql.SQLException;
public abstract boolean supportsSelectForUpdate() throws java.sql.SQLException;
public abstract boolean supportsStoredProcedures() throws java.sql.SQLException;
public abstract boolean supportsSubqueriesInComparisons() throws java.sql.SQLException;
public abstract boolean supportsSubqueriesInExists() throws java.sql.SQLException;
public abstract boolean supportsSubqueriesInIns() throws java.sql.SQLException;
public abstract boolean supportsSubqueriesInQuantifieds() throws java.sql.SQLException;
public abstract boolean supportsCorrelatedSubqueries() throws java.sql.SQLException;
public abstract boolean supportsUnion() throws java.sql.SQLException;
public abstract boolean supportsUnionAll() throws java.sql.SQLException;
public abstract boolean supportsOpenCursorsAcrossCommit() throws java.sql.SQLException;
public abstract boolean supportsOpenCursorsAcrossRollback() throws java.sql.SQLException;
public abstract boolean supportsOpenStatementsAcrossCommit() throws java.sql.SQLException;
public abstract boolean supportsOpenStatementsAcrossRollback() throws java.sql.SQLException;
public abstract int getMaxBinaryLiteralLength() throws java.sql.SQLException;
public abstract int getMaxCharLiteralLength() throws java.sql.SQLException;
public abstract int getMaxColumnNameLength() throws java.sql.SQLException;
public abstract int getMaxColumnsInGroupBy() throws java.sql.SQLException;
public abstract int getMaxColumnsInIndex() throws java.sql.SQLException;
public abstract int getMaxColumnsInOrderBy() throws java.sql.SQLException;
public abstract int getMaxColumnsInSelect() throws java.sql.SQLException;
public abstract int getMaxColumnsInTable() throws java.sql.SQLException;
public abstract int getMaxConnections() throws java.sql.SQLException;
public abstract int getMaxCursorNameLength() throws java.sql.SQLException;
public abstract int getMaxIndexLength() throws java.sql.SQLException;
public abstract int getMaxSchemaNameLength() throws java.sql.SQLException;
public abstract int getMaxProcedureNameLength() throws java.sql.SQLException;
public abstract int getMaxCatalogNameLength() throws java.sql.SQLException;
public abstract int getMaxRowSize() throws java.sql.SQLException;
public abstract boolean doesMaxRowSizeIncludeBlobs() throws java.sql.SQLException;
public abstract int getMaxStatementLength() throws java.sql.SQLException;
public abstract int getMaxStatements() throws java.sql.SQLException;
public abstract int getMaxTableNameLength() throws java.sql.SQLException;
public abstract int getMaxTablesInSelect() throws java.sql.SQLException;
public abstract int getMaxUserNameLength() throws java.sql.SQLException;
public abstract int getDefaultTransactionIsolation() throws java.sql.SQLException;
public abstract boolean supportsTransactions() throws java.sql.SQLException;
public abstract boolean supportsTransactionIsolationLevel(int) throws java.sql.SQLException;
public abstract boolean supportsDataDefinitionAndDataManipulationTransactions() throws java.sql.SQLException;
public abstract boolean supportsDataManipulationTransactionsOnly() throws java.sql.SQLException;
public abstract boolean dataDefinitionCausesTransactionCommit() throws java.sql.SQLException;
public abstract boolean dataDefinitionIgnoredInTransactions() throws java.sql.SQLException;
public abstract java.sql.ResultSet getProcedures(java.lang.String, java.lang.String, java.lang.String) throws java.sql.SQLException;
public abstract java.sql.ResultSet getProcedureColumns(java.lang.String, java.lang.String, java.lang.String, java.lang.String) throws java.sql.SQLException;
public abstract java.sql.ResultSet getTables(java.lang.String, java.lang.String, java.lang.String, java.lang.String[]) throws java.sql.SQLException;
public abstract java.sql.ResultSet getSchemas() throws java.sql.SQLException;
public abstract java.sql.ResultSet getCatalogs() throws java.sql.SQLException;
public abstract java.sql.ResultSet getTableTypes() throws java.sql.SQLException;
public abstract java.sql.ResultSet getColumns(java.lang.String, java.lang.String, java.lang.String, java.lang.String) throws java.sql.SQLException;
public abstract java.sql.ResultSet getColumnPrivileges(java.lang.String, java.lang.String, java.lang.String, java.lang.String) throws java.sql.SQLException;
public abstract java.sql.ResultSet getTablePrivileges(java.lang.String, java.lang.String, java.lang.String) throws java.sql.SQLException;
public abstract java.sql.ResultSet getBestRowIdentifier(java.lang.String, java.lang.String, java.lang.String, int, boolean) throws java.sql.SQLException;
public abstract java.sql.ResultSet getVersionColumns(java.lang.String, java.lang.String, java.lang.String) throws java.sql.SQLException;
public abstract java.sql.ResultSet getPrimaryKeys(java.lang.String, java.lang.String, java.lang.String) throws java.sql.SQLException;
public abstract java.sql.ResultSet getImportedKeys(java.lang.String, java.lang.String, java.lang.String) throws java.sql.SQLException;
public abstract java.sql.ResultSet getExportedKeys(java.lang.String, java.lang.String, java.lang.String) throws java.sql.SQLException;
public abstract java.sql.ResultSet getCrossReference(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) throws java.sql.SQLException;
public abstract java.sql.ResultSet getTypeInfo() throws java.sql.SQLException;
public abstract java.sql.ResultSet getIndexInfo(java.lang.String, java.lang.String, java.lang.String, boolean, boolean) throws java.sql.SQLException;
public abstract boolean supportsResultSetType(int) throws java.sql.SQLException;
public abstract boolean supportsResultSetConcurrency(int, int) throws java.sql.SQLException;
public abstract boolean ownUpdatesAreVisible(int) throws java.sql.SQLException;
public abstract boolean ownDeletesAreVisible(int) throws java.sql.SQLException;
public abstract boolean ownInsertsAreVisible(int) throws java.sql.SQLException;
public abstract boolean othersUpdatesAreVisible(int) throws java.sql.SQLException;
public abstract boolean othersDeletesAreVisible(int) throws java.sql.SQLException;
public abstract boolean othersInsertsAreVisible(int) throws java.sql.SQLException;
public abstract boolean updatesAreDetected(int) throws java.sql.SQLException;
public abstract boolean deletesAreDetected(int) throws java.sql.SQLException;
public abstract boolean insertsAreDetected(int) throws java.sql.SQLException;
public abstract boolean supportsBatchUpdates() throws java.sql.SQLException;
public abstract java.sql.ResultSet getUDTs(java.lang.String, java.lang.String, java.lang.String, int[]) throws java.sql.SQLException;
public abstract java.sql.Connection getConnection() throws java.sql.SQLException;
public abstract boolean supportsSavepoints() throws java.sql.SQLException;
public abstract boolean supportsNamedParameters() throws java.sql.SQLException;
public abstract boolean supportsMultipleOpenResults() throws java.sql.SQLException;
public abstract boolean supportsGetGeneratedKeys() throws java.sql.SQLException;
public abstract java.sql.ResultSet getSuperTypes(java.lang.String, java.lang.String, java.lang.String) throws java.sql.SQLException;
public abstract java.sql.ResultSet getSuperTables(java.lang.String, java.lang.String, java.lang.String) throws java.sql.SQLException;
public abstract java.sql.ResultSet getAttributes(java.lang.String, java.lang.String, java.lang.String, java.lang.String) throws java.sql.SQLException;
public abstract boolean supportsResultSetHoldability(int) throws java.sql.SQLException;
public abstract int getResultSetHoldability() throws java.sql.SQLException;
public abstract int getDatabaseMajorVersion() throws java.sql.SQLException;
public abstract int getDatabaseMinorVersion() throws java.sql.SQLException;
public abstract int getJDBCMajorVersion() throws java.sql.SQLException;
public abstract int getJDBCMinorVersion() throws java.sql.SQLException;
public abstract int getSQLStateType() throws java.sql.SQLException;
public abstract boolean locatorsUpdateCopy() throws java.sql.SQLException;
public abstract boolean supportsStatementPooling() throws java.sql.SQLException;
public abstract java.sql.RowIdLifetime getRowIdLifetime() throws java.sql.SQLException;
public abstract java.sql.ResultSet getSchemas(java.lang.String, java.lang.String) throws java.sql.SQLException;
public abstract boolean supportsStoredFunctionsUsingCallSyntax() throws java.sql.SQLException;
public abstract boolean autoCommitFailureClosesAllResultSets() throws java.sql.SQLException;
public abstract java.sql.ResultSet getClientInfoProperties() throws java.sql.SQLException;
public abstract java.sql.ResultSet getFunctions(java.lang.String, java.lang.String, java.lang.String) throws java.sql.SQLException;
public abstract java.sql.ResultSet getFunctionColumns(java.lang.String, java.lang.String, java.lang.String, java.lang.String) throws java.sql.SQLException;