Example usage for java.sql DatabaseMetaData getSchemaTerm

List of usage examples for java.sql DatabaseMetaData getSchemaTerm

Introduction

In this page you can find the example usage for java.sql DatabaseMetaData getSchemaTerm.

Prototype

String getSchemaTerm() throws SQLException;

Source Link

Document

Retrieves the database vendor's preferred term for "schema".

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getHSQLConnection();

    DatabaseMetaData md = conn.getMetaData();
    System.out.println(md.getSchemaTerm());

    conn.close();/*from w  w w.  ja v a  2 s . co  m*/
}

From source file:com.alifi.jgenerator.spring.SpringGeneratorFactory.java

public static void main(String[] args) {
    @SuppressWarnings("unused")
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("META-INF/SpringContext.xml");

    for (DataSourceMap m : DataSourceUtil.getDataSourceMap()) {

        DataSource ds = m.getDataSource();
        try {//from   w  w w  .j  av  a2s  . c  o m
            Connection con = ds.getConnection();
            DatabaseMetaData dmd = con.getMetaData();
            String catalog = con.getCatalog();
            String schemaPattern = dmd.getSchemaTerm();
            System.out.println("Catalog:" + con.getCatalog() + " schemaPattern:" + schemaPattern);
            ResultSet rs = dmd.getTables(catalog, schemaPattern, "time_zone_transition", null);

            Statement s = null;
            ResultSet xrs = null;
            try {
                s = con.createStatement();
                xrs = s.executeQuery("select * from time_zone_transition");
                if (xrs.next()) {
                    p("xxxxxxxxxxxxxxxxxxxxxxxx:" + xrs.getString(1));
                }
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
            }

            while (rs.next()) {
                p("-----------------------");
                p("TABLE_CAT  :" + rs.getString("TABLE_CAT"));
                p("TABLE_SCHEM:" + rs.getString("TABLE_SCHEM"));
                p("TABLE_NAME :" + rs.getString("TABLE_NAME"));
                p("TABLE_TYPE :" + rs.getString("TABLE_TYPE"));
                p("REMARKS:   " + rs.getString("REMARKS"));

                p("11111111111111111:" + rs.getMetaData().getColumnClassName(1));
                // 
                ResultSet pkeyRs = dmd.getPrimaryKeys(catalog, schemaPattern, rs.getString("TABLE_NAME"));
                while (pkeyRs.next()) {
                    p("M-------------M");
                    p("------COLUMN_NAME:" + pkeyRs.getString("COLUMN_NAME"));
                    p("------KEY_SEQ:" + pkeyRs.getString("KEY_SEQ"));
                    p("------PK_NAME:" + pkeyRs.getString("PK_NAME"));
                }
                // 
                ResultSet rss = dmd.getColumns(catalog, schemaPattern, rs.getString("TABLE_NAME"), null);
                int cCount = rss.getMetaData().getColumnCount();
                for (int i = 1; i <= cCount; i++) {
                    p("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
                    p("       getColumnClassName:" + rss.getMetaData().getColumnClassName(i));
                    p("       getColumnLabel:" + rss.getMetaData().getColumnLabel(i));
                    p("       getColumnName:" + rss.getMetaData().getColumnName(i));
                    p("       getColumnTypeName:" + rss.getMetaData().getColumnTypeName(i));
                    p("       getColumnType:" + ColumnTypes.getType(rss.getMetaData().getColumnType(i)));
                }
            }
            rs = dmd.getTableTypes();

            while (rs.next()) {
                p("=========================");
                p("TABLE_TYPE: " + rs.getString("TABLE_TYPE"));
            }
            // ResultSetMetaData rsmd = rs.getMetaData();

            // int numberOfColumns = rsmd.getColumnCount();
            // for (int i = 1; i <= numberOfColumns; i++)
            // p(rsmd.getColumnName(i));
        } catch (SQLException e) {
            e.printStackTrace();
        }

        p(m.toString());
    }
}

From source file:net.certifi.audittablegen.AuditTableGen.java

/**
 * Examines the DataSource metadata for information pertaining to the
 * driver, catalog, schema and the presence of audit table configuration
 * data./*ww  w.ja va2 s  . com*/
 * 
 * @return String containing datasource information.
 * @throws SQLException 
 */
String getDataSourceInfo() throws SQLException {

    Connection conn = dataSource.getConnection();
    DatabaseMetaData dmd = conn.getMetaData();
    StringBuilder s = new StringBuilder();

    s.append("Driver Name: ").append(dmd.getDriverName()).append("Driver Version: ")
            .append(dmd.getDriverVersion()).append(System.lineSeparator()).append("CatalogSeperator: ")
            .append(dmd.getCatalogSeparator()).append(System.lineSeparator()).append("CatalogTerm: ")
            .append(dmd.getCatalogTerm()).append(System.lineSeparator()).append("SchemaTerm: ")
            .append(dmd.getSchemaTerm()).append(System.lineSeparator()).append("Catalogs: ");

    ResultSet rs = dmd.getCatalogs();
    while (rs.next()) {
        s.append(rs.getString("TABLE_CAT")).append(",");
        logger.debug("Catalog: {}", rs.getString("TABLE_CAT"));
    }
    rs.close();
    s.append(System.lineSeparator());

    s.append("Schemas: ");
    rs = dmd.getSchemas();
    while (rs.next()) {
        logger.debug("Schema: {}", rs.getString("TABLE_SCHEM"));
        s.append("{catalog}:").append(rs.getString("TABLE_CATALOG")).append(" {schema}:")
                .append(rs.getString("TABLE_SCHEM")).append(",");
    }
    rs.close();
    s.append(System.lineSeparator()).append("Target Catalog: ").append(catalog).append(System.lineSeparator())
            .append("Target Schema: ").append(schema).append(System.lineSeparator());

    //       if (dmr.hasAuditConfigTable()){
    //           s.append("Has auditConfigSource table").append(System.lineSeparator());
    //       }

    conn.close();

    return s.toString();

}

From source file:ca.sqlpower.sqlobject.SQLObject.java

/**
 * Returns true if this SQLObject is definitely a container for SQLTable
 * objects. Depending on the source database topology, instances of
 * SQLDatabase, SQLCatalog, and SQLSchema may return true. Other types of
 * SQLObject will always return false, since there is no topology in which
 * they are table containers. Calling this method will never result in
 * populating an unpopulated SQLObject.//from   w  ww .j  a v a2 s. c  om
 * <p>
 * If this SQLObject is populated and has at least one child, this method
 * makes the determination cheap and accurate by checking if the children
 * are of type SQLTable. Otherwise, the object has no children (whether or
 * not it is populated), so this method examines the JDBC driver's database
 * metadata to determine the topology based on the reported catalogTerm and
 * schemaTerm. A null value for either term is interpreted to mean the
 * database does not have that level of object containment. The (major)
 * downside of this approach is that it does not work when the database
 * connection is unavailable.
 * 
 * @return
 * @throws SQLObjectException
 *             if the determination requires database metadata access, and
 *             it's not possible to obtain the database connection or the
 *             database metadata.
 */
@NonProperty
public boolean isTableContainer() throws SQLObjectException {

    // first, check for existing SQLTable children--this is a dead giveaway for a table container!
    if (getChildrenWithoutPopulating().size() > 0) {
        return (getChildrenWithoutPopulating(SQLTable.class).size() != 0);
    }

    // no children. we have to do a bit of structural investigation.

    // schemas can only contain tables
    if (getClass() == SQLSchema.class) {
        return true;
    }

    // determination for catalogs and databases requires database metadata
    Connection con = null;
    try {

        // catalogs could contain schemas or tables. If schemaTerm is null, it must be tables.
        if (getClass() == SQLCatalog.class) {
            SQLDatabase db = (SQLDatabase) getParent();
            con = db.getConnection();
            if (con == null) {
                throw new SQLObjectException(
                        "Unable to determine table container status without database connection");
            }
            DatabaseMetaData dbmd = con.getMetaData();
            return dbmd.getSchemaTerm() == null;
        }

        // databases could contain catalogs, schemas, or tables
        if (getClass() == SQLDatabase.class) {
            SQLDatabase db = (SQLDatabase) this;
            con = db.getConnection();
            if (con == null) {
                throw new SQLObjectException(
                        "Unable to determine table container status without database connection");
            }
            DatabaseMetaData dbmd = con.getMetaData();
            return (dbmd.getSchemaTerm() == null) && (dbmd.getCatalogTerm() == null);
        }
    } catch (SQLException ex) {
        throw new SQLObjectException("Failed to obtain database metadata", ex);
    } finally {
        try {
            if (con != null)
                con.close();
        } catch (SQLException ex) {
            logger.warn("Failed to close connection", ex);
        }
    }

    // other types of SQLObject are never table containers
    return false;
}

From source file:com.micromux.cassandra.jdbc.JdbcRegressionTest.java

/**
 * Create a column group and confirm that the {@code ResultSetMetaData} works.
 *///ww  w.jav  a  2s .  co m
@Test
public void testResultSetMetaData() throws Exception {

    Statement stmt = con.createStatement();

    // Create the target Column family
    String createCF = "CREATE COLUMNFAMILY t33 (k int PRIMARY KEY," + "c text " + ") ;";

    stmt.execute(createCF);
    stmt.close();
    con.close();

    // open it up again to see the new CF
    con = DriverManager
            .getConnection(String.format("jdbc:cassandra://%s:%d/%s?%s", HOST, PORT, KEYSPACE, OPTIONS));

    // paraphrase of the snippet from the ISSUE #33 provided test
    PreparedStatement statement = con.prepareStatement("update t33 set c=? where k=123");
    statement.setString(1, "mark");
    statement.executeUpdate();

    ResultSet result = statement.executeQuery("SELECT k, c FROM t33;");

    ResultSetMetaData metadata = result.getMetaData();

    int colCount = metadata.getColumnCount();

    System.out.println("Test Issue #33");
    DatabaseMetaData md = con.getMetaData();
    System.out.println();
    System.out.println("--------------");
    System.out.println("Driver Version :   " + md.getDriverVersion());
    System.out.println("DB Version     :   " + md.getDatabaseProductVersion());
    System.out.println("Catalog term   :   " + md.getCatalogTerm());
    System.out.println("Catalog        :   " + con.getCatalog());
    System.out.println("Schema term    :   " + md.getSchemaTerm());

    System.out.println("--------------");
    while (result.next()) {
        metadata = result.getMetaData();
        colCount = metadata.getColumnCount();

        assertEquals("Total column count should match schema for t33", 2, metadata.getColumnCount());

        System.out.printf("(%d) ", result.getRow());
        for (int i = 1; i <= colCount; i++) {
            System.out.print(showColumn(i, result) + " ");

            switch (i) {
            case 1:
                assertEquals("First Column: k", "k", metadata.getColumnName(1));
                assertEquals("First Column Type: int", Types.INTEGER, metadata.getColumnType(1));
                break;
            case 2:
                assertEquals("Second Column: c", "c", metadata.getColumnName(2));
                assertEquals("Second Column Type: text", Types.NVARCHAR, metadata.getColumnType(2));
                break;
            }
        }
        System.out.println();
    }
}

From source file:ca.sqlpower.sqlobject.SQLDatabase.java

protected synchronized void populateImpl() throws SQLObjectException {
    logger.debug("SQLDatabase: is populated " + populated); //$NON-NLS-1$
    if (populated)
        return;//from   ww  w . j  a va 2s. c o  m

    logger.debug("SQLDatabase: populate starting"); //$NON-NLS-1$

    Connection con = null;
    ResultSet rs = null;
    final List<SQLCatalog> fetchedCatalogs;
    final List<SQLSchema> fetchedSchemas;
    final List<SQLTable> fetchedTables;
    try {
        con = getConnection();
        DatabaseMetaData dbmd = con.getMetaData();

        catalogTerm = dbmd.getCatalogTerm();
        if ("".equals(catalogTerm)) //$NON-NLS-1$
            catalogTerm = null;

        schemaTerm = dbmd.getSchemaTerm();
        if ("".equals(schemaTerm)) //$NON-NLS-1$
            schemaTerm = null;

        fetchedCatalogs = SQLCatalog.fetchCatalogs(dbmd);

        // If there were no catalogs, we should look for schemas
        // instead (i.e. this database has no catalogs, and schemas
        // may be attached directly to the database)
        if (fetchedCatalogs.isEmpty()) {
            fetchedSchemas = SQLSchema.fetchSchemas(dbmd, null);
        } else {
            fetchedSchemas = null;
        }

        // Finally, look for tables directly under the database (this
        // could be a platform without catalogs or schemas at all)
        if (fetchedCatalogs.isEmpty() && fetchedSchemas.isEmpty()) {
            fetchedTables = SQLTable.fetchTablesForTableContainer(dbmd, "", ""); //$NON-NLS-1$ //$NON-NLS-2$
        } else {
            fetchedTables = null;
        }

    } catch (SQLException e) {
        throw new SQLObjectException(Messages.getString("SQLDatabase.populateFailed"), e); //$NON-NLS-1$
    } finally {
        try {
            if (rs != null)
                rs.close();
        } catch (SQLException e2) {
            throw new SQLObjectException(Messages.getString("SQLDatabase.closeRSFailed"), e2); //$NON-NLS-1$
        }
        try {
            if (con != null)
                con.close();
        } catch (SQLException e2) {
            throw new SQLObjectException(Messages.getString("SQLDatabase.closeConFailed"), e2); //$NON-NLS-1$
        }
    }
    runInForeground(new Runnable() {

        public void run() {
            synchronized (SQLDatabase.this) {
                if (populated)
                    return;
                if (!fetchedCatalogs.isEmpty()) {
                    populateDatabaseWithList(SQLDatabase.this, fetchedCatalogs);
                } else if (!fetchedSchemas.isEmpty()) {
                    populateDatabaseWithList(SQLDatabase.this, fetchedSchemas);
                } else if (!fetchedTables.isEmpty()) {
                    populateDatabaseWithList(SQLDatabase.this, fetchedTables);
                }
            }
        }
    });

    logger.debug("SQLDatabase: populate finished"); //$NON-NLS-1$
}

From source file:it.eng.spagobi.meta.initializer.PhysicalModelInitializer.java

private void addSchema(DatabaseMetaData dbMeta, PhysicalModel model, String defaultSchema) {
    String schema;/*from  w  w  w .  ja  va  2 s.  c om*/
    List<String> schemas;
    ResultSet rs;
    Iterator<String> it;

    schema = null;

    try {
        rs = dbMeta.getSchemas();
        schemas = new ArrayList();
        while (rs.next()) {
            String schemaName = rs.getString(1);
            if (schemaName != null) {
                schemas.add(rs.getString(1));
            }
        }

        if (schemas.size() == 0) {
            log("No schema [" + dbMeta.getSchemaTerm() + "] defined");
        } else if (schemas.size() == 1) {
            schema = schemas.get(1);
        } else {
            String targetSchema = null;
            it = schemas.iterator();
            while (it.hasNext()) {
                String s = it.next();
                if (s.equalsIgnoreCase(defaultSchema)) {
                    targetSchema = defaultSchema;
                    break;
                }
            }
            if (targetSchema == null) {
                throw new RuntimeException("No schema named [" + defaultSchema + "] is available on db");
            }
            schema = targetSchema;
        }
        rs.close();
        model.setSchema(schema);
    } catch (Throwable t) {
        throw new RuntimeException("Impossible to initialize schema metadata", t);
    }
}

From source file:it.eng.spagobi.meta.initializer.PhysicalModelInitializer.java

private void addCatalog(Connection conn, PhysicalModel model, String defaultCatalog) {
    String catalog;//from  w w w .  ja va  2 s. c  o m
    List<String> catalogs;
    DatabaseMetaData dbMeta;
    ResultSet rs;
    Iterator<String> it;

    catalog = null;

    try {

        catalog = conn.getCatalog();
        if (catalog == null) {
            dbMeta = conn.getMetaData();

            rs = dbMeta.getCatalogs();
            catalogs = new ArrayList();
            while (rs.next()) {
                String catalogName = rs.getString(1);
                if (catalogName != null) {
                    catalogs.add(catalogName);
                }
            }
            if (catalogs.size() == 0) {
                log("No schema [" + dbMeta.getSchemaTerm() + "] defined");
            } else if (catalogs.size() == 1) {
                catalog = catalogs.get(1);
            } else {
                String targetCatalog = null;
                it = catalogs.iterator();
                while (it.hasNext()) {
                    String s = it.next();
                    log("s [" + s + "]");
                    if (s.equalsIgnoreCase(defaultCatalog)) {
                        targetCatalog = defaultCatalog;
                        break;
                    }
                }
                if (targetCatalog == null) {
                    throw new RuntimeException("No catalog named [" + defaultCatalog + "] is available on db");
                }
                catalog = targetCatalog;
            }
            rs.close();
        }

        model.setCatalog(catalog);
    } catch (Throwable t) {
        throw new RuntimeException("Impossible to initialize catalog metadata", t);
    }
}

From source file:org.apache.bigtop.itest.hive.TestJdbc.java

/**
 * Test simple DatabaseMetaData calls.  getColumns is tested elsewhere, as we need to call
 * that on a valid table.  Same with getFunctions.
 *
 * @throws SQLException/* w  ww  .ja  v a 2  s.co m*/
 */
@Test
public void databaseMetaDataCalls() throws SQLException {
    DatabaseMetaData md = conn.getMetaData();

    boolean boolrc = md.allTablesAreSelectable();
    LOG.debug("All tables are selectable? " + boolrc);

    String strrc = md.getCatalogSeparator();
    LOG.debug("Catalog separator " + strrc);

    strrc = md.getCatalogTerm();
    LOG.debug("Catalog term " + strrc);

    ResultSet rs = md.getCatalogs();
    while (rs.next()) {
        strrc = rs.getString(1);
        LOG.debug("Found catalog " + strrc);
    }

    Connection c = md.getConnection();

    int intrc = md.getDatabaseMajorVersion();
    LOG.debug("DB major version is " + intrc);

    intrc = md.getDatabaseMinorVersion();
    LOG.debug("DB minor version is " + intrc);

    strrc = md.getDatabaseProductName();
    LOG.debug("DB product name is " + strrc);

    strrc = md.getDatabaseProductVersion();
    LOG.debug("DB product version is " + strrc);

    intrc = md.getDefaultTransactionIsolation();
    LOG.debug("Default transaction isolation is " + intrc);

    intrc = md.getDriverMajorVersion();
    LOG.debug("Driver major version is " + intrc);

    intrc = md.getDriverMinorVersion();
    LOG.debug("Driver minor version is " + intrc);

    strrc = md.getDriverName();
    LOG.debug("Driver name is " + strrc);

    strrc = md.getDriverVersion();
    LOG.debug("Driver version is " + strrc);

    strrc = md.getExtraNameCharacters();
    LOG.debug("Extra name characters is " + strrc);

    strrc = md.getIdentifierQuoteString();
    LOG.debug("Identifier quote string is " + strrc);

    // In Hive 1.2 this always returns an empty RS
    rs = md.getImportedKeys("a", "b", "d");

    // In Hive 1.2 this always returns an empty RS
    rs = md.getIndexInfo("a", "b", "d", true, true);

    intrc = md.getJDBCMajorVersion();
    LOG.debug("JDBC major version is " + intrc);

    intrc = md.getJDBCMinorVersion();
    LOG.debug("JDBC minor version is " + intrc);

    intrc = md.getMaxColumnNameLength();
    LOG.debug("Maximum column name length is " + intrc);

    strrc = md.getNumericFunctions();
    LOG.debug("Numeric functions are " + strrc);

    // In Hive 1.2 this always returns an empty RS
    rs = md.getPrimaryKeys("a", "b", "d");

    // In Hive 1.2 this always returns an empty RS
    rs = md.getProcedureColumns("a", "b", "d", "e");

    strrc = md.getProcedureTerm();
    LOG.debug("Procedures are called " + strrc);

    // In Hive 1.2 this always returns an empty RS
    rs = md.getProcedures("a", "b", "d");

    strrc = md.getSchemaTerm();
    LOG.debug("Schemas are called " + strrc);

    rs = md.getSchemas();
    while (rs.next()) {
        strrc = rs.getString(1);
        LOG.debug("Found schema " + strrc);
    }

    strrc = md.getSearchStringEscape();
    LOG.debug("Search string escape is " + strrc);

    strrc = md.getStringFunctions();
    LOG.debug("String functions are " + strrc);

    strrc = md.getSystemFunctions();
    LOG.debug("System functions are " + strrc);

    rs = md.getTableTypes();
    while (rs.next()) {
        strrc = rs.getString(1);
        LOG.debug("Found table type " + strrc);
    }

    strrc = md.getTimeDateFunctions();
    LOG.debug("Time/date functions are " + strrc);

    rs = md.getTypeInfo();
    while (rs.next()) {
        strrc = rs.getString(1);
        LOG.debug("Found type " + strrc);
    }

    // In Hive 1.2 this always returns an empty RS
    rs = md.getUDTs("a", "b", "d", null);

    boolrc = md.supportsAlterTableWithAddColumn();
    LOG.debug("Supports alter table with add column? " + boolrc);

    boolrc = md.supportsAlterTableWithDropColumn();
    LOG.debug("Supports alter table with drop column? " + boolrc);

    boolrc = md.supportsBatchUpdates();
    LOG.debug("Supports batch updates? " + boolrc);

    boolrc = md.supportsCatalogsInDataManipulation();
    LOG.debug("Supports catalogs in data manipulation? " + boolrc);

    boolrc = md.supportsCatalogsInIndexDefinitions();
    LOG.debug("Supports catalogs in index definition? " + boolrc);

    boolrc = md.supportsCatalogsInPrivilegeDefinitions();
    LOG.debug("Supports catalogs in privilege definition? " + boolrc);

    boolrc = md.supportsCatalogsInProcedureCalls();
    LOG.debug("Supports catalogs in procedure calls? " + boolrc);

    boolrc = md.supportsCatalogsInTableDefinitions();
    LOG.debug("Supports catalogs in table definition? " + boolrc);

    boolrc = md.supportsColumnAliasing();
    LOG.debug("Supports column aliasing? " + boolrc);

    boolrc = md.supportsFullOuterJoins();
    LOG.debug("Supports full outer joins? " + boolrc);

    boolrc = md.supportsGroupBy();
    LOG.debug("Supports group by? " + boolrc);

    boolrc = md.supportsLimitedOuterJoins();
    LOG.debug("Supports limited outer joins? " + boolrc);

    boolrc = md.supportsMultipleResultSets();
    LOG.debug("Supports limited outer joins? " + boolrc);

    boolrc = md.supportsNonNullableColumns();
    LOG.debug("Supports non-nullable columns? " + boolrc);

    boolrc = md.supportsOuterJoins();
    LOG.debug("Supports outer joins? " + boolrc);

    boolrc = md.supportsPositionedDelete();
    LOG.debug("Supports positioned delete? " + boolrc);

    boolrc = md.supportsPositionedUpdate();
    LOG.debug("Supports positioned update? " + boolrc);

    boolrc = md.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
    LOG.debug("Supports result set holdability? " + boolrc);

    boolrc = md.supportsResultSetType(ResultSet.HOLD_CURSORS_OVER_COMMIT);
    LOG.debug("Supports result set type? " + boolrc);

    boolrc = md.supportsSavepoints();
    LOG.debug("Supports savepoints? " + boolrc);

    boolrc = md.supportsSchemasInDataManipulation();
    LOG.debug("Supports schemas in data manipulation? " + boolrc);

    boolrc = md.supportsSchemasInIndexDefinitions();
    LOG.debug("Supports schemas in index definitions? " + boolrc);

    boolrc = md.supportsSchemasInPrivilegeDefinitions();
    LOG.debug("Supports schemas in privilege definitions? " + boolrc);

    boolrc = md.supportsSchemasInProcedureCalls();
    LOG.debug("Supports schemas in procedure calls? " + boolrc);

    boolrc = md.supportsSchemasInTableDefinitions();
    LOG.debug("Supports schemas in table definitions? " + boolrc);

    boolrc = md.supportsSelectForUpdate();
    LOG.debug("Supports select for update? " + boolrc);

    boolrc = md.supportsStoredProcedures();
    LOG.debug("Supports stored procedures? " + boolrc);

    boolrc = md.supportsTransactions();
    LOG.debug("Supports transactions? " + boolrc);

    boolrc = md.supportsUnion();
    LOG.debug("Supports union? " + boolrc);

    boolrc = md.supportsUnionAll();
    LOG.debug("Supports union all? " + boolrc);

}

From source file:org.apache.openjpa.jdbc.sql.DBDictionaryFactory.java

/**
 * Return a string containing all the property values of the given
 * database metadata./*www.ja  va  2  s.c  om*/
 */
public static String toString(DatabaseMetaData meta) throws SQLException {
    String lineSep = J2DoPrivHelper.getLineSeparator();
    StringBuilder buf = new StringBuilder(4096);
    try {
        buf.append("catalogSeparator: ").append(meta.getCatalogSeparator()).append(lineSep)
                .append("catalogTerm: ").append(meta.getCatalogTerm()).append(lineSep)
                .append("databaseProductName: ").append(meta.getDatabaseProductName()).append(lineSep)
                .append("databaseProductVersion: ").append(meta.getDatabaseProductVersion()).append(lineSep)
                .append("driverName: ").append(meta.getDriverName()).append(lineSep).append("driverVersion: ")
                .append(meta.getDriverVersion()).append(lineSep).append("extraNameCharacters: ")
                .append(meta.getExtraNameCharacters()).append(lineSep).append("identifierQuoteString: ")
                .append(meta.getIdentifierQuoteString()).append(lineSep).append("numericFunctions: ")
                .append(meta.getNumericFunctions()).append(lineSep).append("procedureTerm: ")
                .append(meta.getProcedureTerm()).append(lineSep).append("schemaTerm: ")
                .append(meta.getSchemaTerm()).append(lineSep).append("searchStringEscape: ")
                .append(meta.getSearchStringEscape()).append(lineSep).append("sqlKeywords: ")
                .append(meta.getSQLKeywords()).append(lineSep).append("stringFunctions: ")
                .append(meta.getStringFunctions()).append(lineSep).append("systemFunctions: ")
                .append(meta.getSystemFunctions()).append(lineSep).append("timeDateFunctions: ")
                .append(meta.getTimeDateFunctions()).append(lineSep).append("url: ").append(meta.getURL())
                .append(lineSep).append("userName: ").append(meta.getUserName()).append(lineSep)
                .append("defaultTransactionIsolation: ").append(meta.getDefaultTransactionIsolation())
                .append(lineSep).append("driverMajorVersion: ").append(meta.getDriverMajorVersion())
                .append(lineSep).append("driverMinorVersion: ").append(meta.getDriverMinorVersion())
                .append(lineSep).append("maxBinaryLiteralLength: ").append(meta.getMaxBinaryLiteralLength())
                .append(lineSep).append("maxCatalogNameLength: ").append(meta.getMaxCatalogNameLength())
                .append(lineSep).append("maxCharLiteralLength: ").append(meta.getMaxCharLiteralLength())
                .append(lineSep).append("maxColumnNameLength: ").append(meta.getMaxColumnNameLength())
                .append(lineSep).append("maxColumnsInGroupBy: ").append(meta.getMaxColumnsInGroupBy())
                .append(lineSep).append("maxColumnsInIndex: ").append(meta.getMaxColumnsInIndex())
                .append(lineSep).append("maxColumnsInOrderBy: ").append(meta.getMaxColumnsInOrderBy())
                .append(lineSep).append("maxColumnsInSelect: ").append(meta.getMaxColumnsInSelect())
                .append(lineSep).append("maxColumnsInTable: ").append(meta.getMaxColumnsInTable())
                .append(lineSep).append("maxConnections: ").append(meta.getMaxConnections()).append(lineSep)
                .append("maxCursorNameLength: ").append(meta.getMaxCursorNameLength()).append(lineSep)
                .append("maxIndexLength: ").append(meta.getMaxIndexLength()).append(lineSep)
                .append("maxProcedureNameLength: ").append(meta.getMaxProcedureNameLength()).append(lineSep)
                .append("maxRowSize: ").append(meta.getMaxRowSize()).append(lineSep)
                .append("maxSchemaNameLength: ").append(meta.getMaxSchemaNameLength()).append(lineSep)
                .append("maxStatementLength: ").append(meta.getMaxStatementLength()).append(lineSep)
                .append("maxStatements: ").append(meta.getMaxStatements()).append(lineSep)
                .append("maxTableNameLength: ").append(meta.getMaxTableNameLength()).append(lineSep)
                .append("maxTablesInSelect: ").append(meta.getMaxTablesInSelect()).append(lineSep)
                .append("maxUserNameLength: ").append(meta.getMaxUserNameLength()).append(lineSep)
                .append("isCatalogAtStart: ").append(meta.isCatalogAtStart()).append(lineSep)
                .append("isReadOnly: ").append(meta.isReadOnly()).append(lineSep)
                .append("nullPlusNonNullIsNull: ").append(meta.nullPlusNonNullIsNull()).append(lineSep)
                .append("nullsAreSortedAtEnd: ").append(meta.nullsAreSortedAtEnd()).append(lineSep)
                .append("nullsAreSortedAtStart: ").append(meta.nullsAreSortedAtStart()).append(lineSep)
                .append("nullsAreSortedHigh: ").append(meta.nullsAreSortedHigh()).append(lineSep)
                .append("nullsAreSortedLow: ").append(meta.nullsAreSortedLow()).append(lineSep)
                .append("storesLowerCaseIdentifiers: ").append(meta.storesLowerCaseIdentifiers())
                .append(lineSep).append("storesLowerCaseQuotedIdentifiers: ")
                .append(meta.storesLowerCaseQuotedIdentifiers()).append(lineSep)
                .append("storesMixedCaseIdentifiers: ").append(meta.storesMixedCaseIdentifiers())
                .append(lineSep).append("storesMixedCaseQuotedIdentifiers: ")
                .append(meta.storesMixedCaseQuotedIdentifiers()).append(lineSep)
                .append("storesUpperCaseIdentifiers: ").append(meta.storesUpperCaseIdentifiers())
                .append(lineSep).append("storesUpperCaseQuotedIdentifiers: ")
                .append(meta.storesUpperCaseQuotedIdentifiers()).append(lineSep)
                .append("supportsAlterTableWithAddColumn: ").append(meta.supportsAlterTableWithAddColumn())
                .append(lineSep).append("supportsAlterTableWithDropColumn: ")
                .append(meta.supportsAlterTableWithDropColumn()).append(lineSep)
                .append("supportsANSI92EntryLevelSQL: ").append(meta.supportsANSI92EntryLevelSQL())
                .append(lineSep).append("supportsANSI92FullSQL: ").append(meta.supportsANSI92FullSQL())
                .append(lineSep).append("supportsANSI92IntermediateSQL: ")
                .append(meta.supportsANSI92IntermediateSQL()).append(lineSep)
                .append("supportsCatalogsInDataManipulation: ")
                .append(meta.supportsCatalogsInDataManipulation()).append(lineSep)
                .append("supportsCatalogsInIndexDefinitions: ")
                .append(meta.supportsCatalogsInIndexDefinitions()).append(lineSep)
                .append("supportsCatalogsInPrivilegeDefinitions: ")
                .append(meta.supportsCatalogsInPrivilegeDefinitions()).append(lineSep)
                .append("supportsCatalogsInProcedureCalls: ").append(meta.supportsCatalogsInProcedureCalls())
                .append(lineSep).append("supportsCatalogsInTableDefinitions: ")
                .append(meta.supportsCatalogsInTableDefinitions()).append(lineSep)
                .append("supportsColumnAliasing: ").append(meta.supportsColumnAliasing()).append(lineSep)
                .append("supportsConvert: ").append(meta.supportsConvert()).append(lineSep)
                .append("supportsCoreSQLGrammar: ").append(meta.supportsCoreSQLGrammar()).append(lineSep)
                .append("supportsCorrelatedSubqueries: ").append(meta.supportsCorrelatedSubqueries())
                .append(lineSep).append("supportsDataDefinitionAndDataManipulationTransactions: ")
                .append(meta.supportsDataDefinitionAndDataManipulationTransactions()).append(lineSep)
                .append("supportsDataManipulationTransactionsOnly: ")
                .append(meta.supportsDataManipulationTransactionsOnly()).append(lineSep)
                .append("supportsDifferentTableCorrelationNames: ")
                .append(meta.supportsDifferentTableCorrelationNames()).append(lineSep)
                .append("supportsExpressionsInOrderBy: ").append(meta.supportsExpressionsInOrderBy())
                .append(lineSep).append("supportsExtendedSQLGrammar: ")
                .append(meta.supportsExtendedSQLGrammar()).append(lineSep).append("supportsFullOuterJoins: ")
                .append(meta.supportsFullOuterJoins()).append(lineSep).append("supportsGroupBy: ")
                .append(meta.supportsGroupBy()).append(lineSep).append("supportsGroupByBeyondSelect: ")
                .append(meta.supportsGroupByBeyondSelect()).append(lineSep).append("supportsGroupByUnrelated: ")
                .append(meta.supportsGroupByUnrelated()).append(lineSep)
                .append("supportsIntegrityEnhancementFacility: ")
                .append(meta.supportsIntegrityEnhancementFacility()).append(lineSep)
                .append("supportsLikeEscapeClause: ").append(meta.supportsLikeEscapeClause()).append(lineSep)
                .append("supportsLimitedOuterJoins: ").append(meta.supportsLimitedOuterJoins()).append(lineSep)
                .append("supportsMinimumSQLGrammar: ").append(meta.supportsMinimumSQLGrammar()).append(lineSep)
                .append("supportsMixedCaseIdentifiers: ").append(meta.supportsMixedCaseIdentifiers())
                .append(lineSep).append("supportsMixedCaseQuotedIdentifiers: ")
                .append(meta.supportsMixedCaseQuotedIdentifiers()).append(lineSep)
                .append("supportsMultipleResultSets: ").append(meta.supportsMultipleResultSets())
                .append(lineSep).append("supportsMultipleTransactions: ")
                .append(meta.supportsMultipleTransactions()).append(lineSep)
                .append("supportsNonNullableColumns: ").append(meta.supportsNonNullableColumns())
                .append(lineSep).append("supportsOpenCursorsAcrossCommit: ")
                .append(meta.supportsOpenCursorsAcrossCommit()).append(lineSep)
                .append("supportsOpenCursorsAcrossRollback: ").append(meta.supportsOpenCursorsAcrossRollback())
                .append(lineSep).append("supportsOpenStatementsAcrossCommit: ")
                .append(meta.supportsOpenStatementsAcrossCommit()).append(lineSep)
                .append("supportsOpenStatementsAcrossRollback: ")
                .append(meta.supportsOpenStatementsAcrossRollback()).append(lineSep)
                .append("supportsOrderByUnrelated: ").append(meta.supportsOrderByUnrelated()).append(lineSep)
                .append("supportsOuterJoins: ").append(meta.supportsOuterJoins()).append(lineSep)
                .append("supportsPositionedDelete: ").append(meta.supportsPositionedDelete()).append(lineSep)
                .append("supportsPositionedUpdate: ").append(meta.supportsPositionedUpdate()).append(lineSep)
                .append("supportsSchemasInDataManipulation: ").append(meta.supportsSchemasInDataManipulation())
                .append(lineSep).append("supportsSchemasInIndexDefinitions: ")
                .append(meta.supportsSchemasInIndexDefinitions()).append(lineSep)
                .append("supportsSchemasInPrivilegeDefinitions: ")
                .append(meta.supportsSchemasInPrivilegeDefinitions()).append(lineSep)
                .append("supportsSchemasInProcedureCalls: ").append(meta.supportsSchemasInProcedureCalls())
                .append(lineSep).append("supportsSchemasInTableDefinitions: ")
                .append(meta.supportsSchemasInTableDefinitions()).append(lineSep)
                .append("supportsSelectForUpdate: ").append(meta.supportsSelectForUpdate()).append(lineSep)
                .append("supportsStoredProcedures: ").append(meta.supportsStoredProcedures()).append(lineSep)
                .append("supportsSubqueriesInComparisons: ").append(meta.supportsSubqueriesInComparisons())
                .append(lineSep).append("supportsSubqueriesInExists: ")
                .append(meta.supportsSubqueriesInExists()).append(lineSep).append("supportsSubqueriesInIns: ")
                .append(meta.supportsSubqueriesInIns()).append(lineSep)
                .append("supportsSubqueriesInQuantifieds: ").append(meta.supportsSubqueriesInQuantifieds())
                .append(lineSep).append("supportsTableCorrelationNames: ")
                .append(meta.supportsTableCorrelationNames()).append(lineSep).append("supportsTransactions: ")
                .append(meta.supportsTransactions()).append(lineSep).append("supportsUnion: ")
                .append(meta.supportsUnion()).append(lineSep).append("supportsUnionAll: ")
                .append(meta.supportsUnionAll()).append(lineSep).append("usesLocalFilePerTable: ")
                .append(meta.usesLocalFilePerTable()).append(lineSep).append("usesLocalFiles: ")
                .append(meta.usesLocalFiles()).append(lineSep).append("allProceduresAreCallable: ")
                .append(meta.allProceduresAreCallable()).append(lineSep).append("allTablesAreSelectable: ")
                .append(meta.allTablesAreSelectable()).append(lineSep)
                .append("dataDefinitionCausesTransactionCommit: ")
                .append(meta.dataDefinitionCausesTransactionCommit()).append(lineSep)
                .append("dataDefinitionIgnoredInTransactions: ")
                .append(meta.dataDefinitionIgnoredInTransactions()).append(lineSep)
                .append("doesMaxRowSizeIncludeBlobs: ").append(meta.doesMaxRowSizeIncludeBlobs())
                .append(lineSep).append("supportsBatchUpdates: ").append(meta.supportsBatchUpdates());
    } catch (Throwable t) {
        // maybe abstract method error for jdbc 3 metadata method, or
        // other error
        buf.append(lineSep).append("Caught throwable: ").append(t);
    }

    return buf.toString();
}