Understanding ResultSetMetaData and DatabaseMetaData

ResultSetMetaData and DatabaseMetaData are JDBC interfaces used to obtain information about database results and the database itself. ResultSetMetaData provides information about the columns returned by a query, such as column names, data types, and number of columns. DatabaseMetaData provides information about the database, JDBC driver, tables, supported features, and database capabilities. Both are useful when developing applications that need to inspect database structures dynamically without knowing all details in advance.

Methods of ResultSetMetaData

Method Signature and Short Description

public int getColumnCount()

Returns the number of columns in the ResultSet.

public String getColumnName(int column)

Returns the name of the specified column.

public String getColumnLabel(int column)

Returns the suggested label for the specified column.

public int getColumnType(int column)

Returns the SQL type of the specified column.

public String getColumnTypeName(int column)

Returns the database-specific type name of the specified column.

public int getColumnDisplaySize(int column)

Returns the normal maximum width of the specified column in characters.

public String getColumnClassName(int column)

Returns the fully qualified Java class name of the column values.

public int getPrecision(int column)

Returns the precision of the specified column.

public int getScale(int column)

Returns the number of digits to the right of the decimal point for the specified column.

public String getTableName(int column)

Returns the name of the table containing the specified column.

public String getSchemaName(int column)

Returns the schema name of the specified column.

public String getCatalogName(int column)

Returns the catalog name of the specified column.

public boolean isAutoIncrement(int column)

Checks whether the specified column is automatically numbered.

public boolean isCaseSensitive(int column)

Checks whether the specified column is case-sensitive.

public boolean isCurrency(int column)

Checks whether the specified column contains a currency value.

public boolean isDefinitelyWritable(int column)

Checks whether a value in the specified column can definitely be written.

public boolean isNullable(int column)

Returns whether the specified column can contain SQL NULL values.

public boolean isReadOnly(int column)

Checks whether the specified column is read-only.

public boolean isSearchable(int column)

Checks whether the specified column can be used in a WHERE clause.

public boolean isSigned(int column)

Checks whether values in the specified column are signed numbers.

public boolean isWritable(int column)

Checks whether a value in the specified column can be written.

Methods of DatabaseMetaData

Method Signature and Short Description

public String getDatabaseProductName()

Returns the name of the database product.

public String getDatabaseProductVersion()

Returns the version number of the database product.

public String getDriverName()

Returns the name of the JDBC driver.

public String getDriverVersion()

Returns the version number of the JDBC driver.

public String getUserName()

Returns the user name used for the current database connection.

public String getURL()

Returns the URL used to establish the database connection.

public boolean isReadOnly()

Checks whether the database connection is read-only.

public int getMaxConnections()

Returns the maximum number of concurrent connections supported by the database.

public int getMaxTablesInSelect()

Returns the maximum number of tables that can be used in a SELECT statement.

public boolean supportsTransactions()

Checks whether the database supports transactions.

public boolean supportsBatchUpdates()

Checks whether the database supports batch updates.

public boolean supportsStoredProcedures()

Checks whether the database supports stored procedures.

public boolean supportsResultSetType(int type)

Checks whether the database supports the specified ResultSet type.

public boolean supportsResultSetConcurrency(int type, int concurrency)

Checks whether the database supports the specified ResultSet type and concurrency mode.

public String getSQLKeywords()

Returns a comma-separated list of database-specific SQL keywords.

public String getNumericFunctions()

Returns a comma-separated list of supported numeric functions.

public String getStringFunctions()

Returns a comma-separated list of supported string functions.

public String getTimeDateFunctions()

Returns a comma-separated list of supported time and date functions.

public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types)

Returns information about tables available in the database.

public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern)

Returns information about columns available in the specified tables.

public ResultSet getPrimaryKeys(String catalog, String schema, String table)

Returns information about the primary keys of the specified table.

public ResultSet getImportedKeys(String catalog, String schema, String table)

Returns information about foreign keys imported by the specified table.

public ResultSet getExportedKeys(String catalog, String schema, String table)

Returns information about foreign keys exported by the specified table.

public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate)

Returns information about indexes and statistics for the specified table.

public String getCatalogTerm()

Returns the database vendor’s preferred term for a catalog.

public String getSchemaTerm()

Returns the database vendor’s preferred term for a schema.

public String getProcedureTerm()

Returns the database vendor’s preferred term for a procedure.

Scroll to Top