JDBC Driver - DatabaseMetaData - Advanced

The JDBC catalog methods return read-only ResultSet objects. Use try-with-resources to close each one. Polypheny uses namespaces as JDBC schemas. For methods accepting a name pattern, % matches any sequence and _ matches one character. Pass null for an unrestricted schema, table or column pattern. Use "%" to enumerate functions. The table and column methods operate on relational entities. To inspect collections, see document collection metadata.

Catalog arguments do not filter these lookups in driver 3.1. Pass null when using ordinary Polypheny connections.

Catalog methods

Method Driver 3.1 behavior
getSchemas(), getSchemas(catalog, schemaPattern) Enumerate namespaces, including document and graph namespaces. Look up TABLE_SCHEM for the namespace name.
getCatalogs() Returns one compatibility row with the server’s default namespace as TABLE_CAT.
getTableTypes() Returns server-provided relational entity types, such as ENTITY and VIEW. Use the returned names to filter getTables.
getTables(catalog, schemaPattern, tableNamePattern, types) Lists matching relational entities. Pass null for all table types. Read TABLE_SCHEM, TABLE_NAME and TABLE_TYPE.
getColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern) Lists relational columns. Read COLUMN_NAME, DATA_TYPE, TYPE_NAME, NULLABLE and ORDINAL_POSITION among other JDBC columns.
getPrimaryKeys(catalog, schema, table) Lists primary key columns and their sequence in the key.
getImportedKeys(catalog, schema, table), getExportedKeys(catalog, schema, table) List foreign keys declared by or referencing a table, respectively.
getCrossReference(parentCatalog, parentSchema, parentTable, foreignCatalog, foreignSchema, foreignTable) Lists matching foreign keys in the foreign table that reference the parent table.
getBestRowIdentifier(catalog, schema, table, scope, nullable) Reports primary key columns as row identifiers. It uses nullable to control inclusion of nullable columns and ignores the requested scope.
getVersionColumns(catalog, schema, table) Returns columns reported by the server as version columns.
getPseudoColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern) Returns matching hidden relational columns.
getIndexInfo(catalog, schema, table, unique, approximate) Lists relational indexes. unique=true filters to unique indexes. approximate is ignored.
getTypeInfo() Returns the Polypheny SQL types advertised by the server.
getFunctions(catalog, schemaPattern, functionNamePattern) Returns matching system SQL functions. Pass a non-null pattern such as "%". The namespace and catalog arguments are ignored.

Optional metadata

The default strict=true mode throws SQLFeatureNotSupportedException for the optional methods in this table. Setting strict=false on the JDBC connection enables their compatibility behavior.

Method Compatibility behavior
getProcedures Requests the server’s SQL procedure list.
getProcedureColumns, getFunctionColumns Return empty result sets.
getColumnPrivileges, getTablePrivileges Produce synthetic privilege rows for matching relational objects. These rows do not represent granted rights.
getSuperTypes, getSuperTables, getAttributes Return empty result sets.
getUDTs, getClientInfoProperties Still throw SQLFeatureNotSupportedException in compatibility mode.

Example: inspect a table and its columns

First run the Statement setup example.

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;

public class InspectTable {
    public static void main(String[] args) throws Exception {
        String url = args.length == 0 ? "jdbc:polypheny://localhost:20590" : args[0];
        try (Connection connection = DriverManager.getConnection(url, "pa", "")) {
            DatabaseMetaData meta = connection.getMetaData();
            try (ResultSet tables = meta.getTables(null, "public", "jdbc_docs_tasks", null)) {
                while (tables.next()) {
                    System.out.printf("%s.%s (%s)%n", tables.getString("TABLE_SCHEM"),
                        tables.getString("TABLE_NAME"), tables.getString("TABLE_TYPE"));
                }
            }
            try (ResultSet columns = meta.getColumns(null, "public", "jdbc_docs_tasks", "%")) {
                while (columns.next()) {
                    System.out.printf("%s.%s (%s)%n", columns.getString("TABLE_NAME"),
                        columns.getString("COLUMN_NAME"), columns.getString("TYPE_NAME"));
                }
            }
        }
    }
}
© Polypheny GmbH. All Rights Reserved.