Example usage for java.sql DatabaseMetaData getDriverVersion

List of usage examples for java.sql DatabaseMetaData getDriverVersion

Introduction

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

Prototype

String getDriverVersion() throws SQLException;

Source Link

Document

Retrieves the version number of this JDBC driver as a String.

Usage

From source file:nl.nn.adapterframework.jdbc.JdbcFacade.java

public String getDatasourceInfo() throws JdbcException {
    String dsinfo = null;//w w w. j a  v a 2 s.  c  o m
    Connection conn = null;
    try {
        conn = getConnection();
        DatabaseMetaData md = conn.getMetaData();
        String product = md.getDatabaseProductName();
        String productVersion = md.getDatabaseProductVersion();
        String driver = md.getDriverName();
        String driverVersion = md.getDriverVersion();
        String url = md.getURL();
        String user = md.getUserName();
        if (getDatabaseType() == DbmsSupportFactory.DBMS_DB2
                && "WAS".equals(IbisContext.getApplicationServerType())
                && md.getResultSetHoldability() != ResultSet.HOLD_CURSORS_OVER_COMMIT) {
            // For (some?) combinations of WebShere and DB2 this seems to be
            // the default and result in the following exception when (for
            // example?) a ResultSetIteratingPipe is calling next() on the
            // ResultSet after it's sender has called a pipeline which
            // contains a GenericMessageSendingPipe using
            // transactionAttribute="NotSupported":
            //   com.ibm.websphere.ce.cm.ObjectClosedException: DSRA9110E: ResultSet is closed.
            ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
            configWarnings.add(log,
                    "The database's default holdability for ResultSet objects is "
                            + md.getResultSetHoldability() + " instead of " + ResultSet.HOLD_CURSORS_OVER_COMMIT
                            + " (ResultSet.HOLD_CURSORS_OVER_COMMIT)");
        }
        dsinfo = "user [" + user + "] url [" + url + "] product [" + product + "] version [" + productVersion
                + "] driver [" + driver + "] version [" + driverVersion + "]";
    } catch (SQLException e) {
        log.warn("Exception determining databaseinfo", e);
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e1) {
                log.warn("exception closing connection for metadata", e1);
            }
        }
    }
    return dsinfo;
}

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 w w  .  ja  v  a2s  .  c  o 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.ddlutils.TestSummaryCreatorTask.java

/**
 * Adds the data from the test jdbc propertis file to the document.
 * /*from   w w  w. j  av a 2 s .co  m*/
 * @param element            The element to add the relevant database properties to
 * @param jdbcPropertiesFile The path of the properties file
 */
protected void addTargetDatabaseInfo(Element element, String jdbcPropertiesFile)
        throws IOException, BuildException {
    if (jdbcPropertiesFile == null) {
        return;
    }

    Properties props = readProperties(jdbcPropertiesFile);
    Connection conn = null;
    DatabaseMetaData metaData = null;

    try {
        String dataSourceClass = props.getProperty(
                TestAgainstLiveDatabaseBase.DATASOURCE_PROPERTY_PREFIX + "class",
                BasicDataSource.class.getName());
        DataSource dataSource = (DataSource) Class.forName(dataSourceClass).newInstance();

        for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
            Map.Entry entry = (Map.Entry) it.next();
            String propName = (String) entry.getKey();

            if (propName.startsWith(TestAgainstLiveDatabaseBase.DATASOURCE_PROPERTY_PREFIX)
                    && !propName.equals(TestAgainstLiveDatabaseBase.DATASOURCE_PROPERTY_PREFIX + "class")) {
                BeanUtils.setProperty(dataSource,
                        propName.substring(TestAgainstLiveDatabaseBase.DATASOURCE_PROPERTY_PREFIX.length()),
                        entry.getValue());
            }
        }

        String platformName = props.getProperty(TestAgainstLiveDatabaseBase.DDLUTILS_PLATFORM_PROPERTY);

        if (platformName == null) {
            platformName = new PlatformUtils().determineDatabaseType(dataSource);
            if (platformName == null) {
                throw new BuildException(
                        "Could not determine platform from datasource, please specify it in the jdbc.properties via the ddlutils.platform property");
            }
        }

        element.addAttribute("platform", platformName);
        element.addAttribute("dataSourceClass", dataSourceClass);

        conn = dataSource.getConnection();
        metaData = conn.getMetaData();

        try {
            element.addAttribute("dbProductName", metaData.getDatabaseProductName());
        } catch (Throwable ex) {
            // we ignore it
        }
        try {
            element.addAttribute("dbProductVersion", metaData.getDatabaseProductVersion());
        } catch (Throwable ex) {
            // we ignore it
        }
        try {
            int databaseMajorVersion = metaData.getDatabaseMajorVersion();
            int databaseMinorVersion = metaData.getDatabaseMinorVersion();

            element.addAttribute("dbVersion", databaseMajorVersion + "." + databaseMinorVersion);
        } catch (Throwable ex) {
            // we ignore it
        }
        try {
            element.addAttribute("driverName", metaData.getDriverName());
        } catch (Throwable ex) {
            // we ignore it
        }
        try {
            element.addAttribute("driverVersion", metaData.getDriverVersion());
        } catch (Throwable ex) {
            // we ignore it
        }
        try {
            int jdbcMajorVersion = metaData.getJDBCMajorVersion();
            int jdbcMinorVersion = metaData.getJDBCMinorVersion();

            element.addAttribute("jdbcVersion", jdbcMajorVersion + "." + jdbcMinorVersion);
        } catch (Throwable ex) {
            // we ignore it
        }
    } catch (Exception ex) {
        throw new BuildException(ex);
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException ex) {
                // we ignore it
            }
        }
    }
}

From source file:org.apache.jackrabbit.core.persistence.db.DatabasePersistenceManager.java

/**
 * {@inheritDoc}/*ww  w .j a v  a2  s .com*/
 */
public void init(PMContext context) throws Exception {
    if (initialized) {
        throw new IllegalStateException("already initialized");
    }

    // setup jdbc connection
    initConnection();

    DatabaseMetaData meta = con.getMetaData();
    try {
        log.info("Database: " + meta.getDatabaseProductName() + " / " + meta.getDatabaseProductVersion());
        log.info("Driver: " + meta.getDriverName() + " / " + meta.getDriverVersion());
    } catch (SQLException e) {
        log.warn("Can not retrieve database and driver name / version", e);
    }

    // make sure schemaObjectPrefix consists of legal name characters only
    prepareSchemaObjectPrefix();

    // check if schema objects exist and create them if necessary
    if (isSchemaCheckEnabled()) {
        checkSchema();
    }

    // build sql statements
    buildSQLStatements();

    // prepare statements
    initPreparedStatements();

    if (externalBLOBs) {
        /**
         * store BLOBs in local file system in a sub directory
         * of the workspace home directory
         */
        LocalFileSystem blobFS = new LocalFileSystem();
        blobFS.setRoot(new File(context.getHomeDir(), "blobs"));
        blobFS.init();
        this.blobFS = blobFS;
        blobStore = new FileSystemBLOBStore(blobFS);
    } else {
        /**
         * store BLOBs in db
         */
        blobStore = new DbBLOBStore();
    }

    initialized = true;
}

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

/**
 * This method is called when the dictionary first sees any connection.
 * It is used to initialize dictionary metadata if needed. If you
 * override this method, be sure to call
 * <code>super.connectedConfiguration</code>.
 *///from w w w. java  2 s  .c om
public void connectedConfiguration(Connection conn) throws SQLException {
    if (!connected) {
        DatabaseMetaData metaData = null;
        try {
            metaData = conn.getMetaData();

            databaseProductName = nullSafe(metaData.getDatabaseProductName());
            databaseProductVersion = nullSafe(metaData.getDatabaseProductVersion());
            setMajorVersion(metaData.getDatabaseMajorVersion());
            setMinorVersion(metaData.getDatabaseMinorVersion());
            try {
                // JDBC3-only method, so it might throw an
                // AbstractMethodError
                int JDBCMajorVersion = metaData.getJDBCMajorVersion();
                isJDBC3 = JDBCMajorVersion >= 3;
                isJDBC4 = JDBCMajorVersion >= 4;
            } catch (Throwable t) {
                // ignore if not JDBC3
            }
        } catch (Exception e) {
            if (log.isTraceEnabled())
                log.trace(e.toString(), e);
        }

        if (log.isTraceEnabled()) {
            log.trace(DBDictionaryFactory.toString(metaData));

            if (isJDBC3) {
                try {
                    log.trace(_loc.get("connection-defaults", new Object[] { conn.getAutoCommit(),
                            conn.getHoldability(), conn.getTransactionIsolation() }));
                } catch (Throwable t) {
                    log.trace("Unable to trace connection settings", t);
                }
            }
        }

        // Configure the naming utility
        if (supportsDelimitedIdentifiers == null) // not explicitly set
            configureNamingUtil(metaData);

        // Auto-detect generated keys retrieval support unless user specified it.
        if (supportsGetGeneratedKeys == null) {
            supportsGetGeneratedKeys = (isJDBC3) ? metaData.supportsGetGeneratedKeys() : false;
        }
        if (log.isInfoEnabled()) {
            log.info(_loc.get("dict-info", new Object[] { metaData.getDatabaseProductName(), getMajorVersion(),
                    getMinorVersion(), metaData.getDriverName(), metaData.getDriverVersion() }));
        }
    }
    connected = true;
}

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

/**
 * Create the dictionary using the given class name and properties; the
 * connection may be null if not supplied to the factory.
 *///from  w  w  w.j  a  v  a  2s  .  c o  m
private static DBDictionary newDBDictionary(JDBCConfiguration conf, String dclass, String props,
        Connection conn) {
    DBDictionary dict = null;
    try {
        Class<?> c = Class.forName(dclass, true,
                AccessController.doPrivileged(J2DoPrivHelper.getClassLoaderAction(DBDictionary.class)));
        dict = (DBDictionary) AccessController.doPrivileged(J2DoPrivHelper.newInstanceAction(c));
    } catch (ClassNotFoundException cnfe) {
        // if the dictionary was not found, make another attempt
        // at loading the dictionary using the current thread.
        try {
            Class<?> c = Thread.currentThread().getContextClassLoader().loadClass(dclass);
            dict = (DBDictionary) AccessController.doPrivileged(J2DoPrivHelper.newInstanceAction(c));
        } catch (Exception e) {
            if (e instanceof PrivilegedActionException)
                e = ((PrivilegedActionException) e).getException();
            throw new UserException(e).setFatal(true);
        }
    } catch (Exception e) {
        if (e instanceof PrivilegedActionException)
            e = ((PrivilegedActionException) e).getException();
        throw new UserException(e).setFatal(true);
    }

    // warn if we could not locate the appropriate dictionary
    Log log = conf.getLog(JDBCConfiguration.LOG_JDBC);
    if (log.isWarnEnabled() && dict.getClass() == DBDictionary.class)
        log.warn(_loc.get("warn-generic"));

    if (log.isInfoEnabled()) {
        String infoString = "";
        if (conn != null) {
            try {
                DatabaseMetaData meta = conn.getMetaData();
                infoString = " (" + meta.getDatabaseProductName() + " " + meta.getDatabaseProductVersion()
                        + " ," + meta.getDriverName() + " " + meta.getDriverVersion() + ")";
            } catch (SQLException se) {
                if (log.isTraceEnabled())
                    log.trace(se.toString(), se);
            }
        }

        log.info(_loc.get("using-dict", dclass, infoString));
    }

    // set the dictionary's metadata
    Configurations.configureInstance(dict, conf, props, "DBDictionary");
    if (conn != null) {
        try {
            dict.connectedConfiguration(conn);
        } catch (SQLException se) {
            throw new StoreException(se).setFatal(true);
        }
    }
    return dict;
}

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

/**
 * Return a string containing all the property values of the given
 * database metadata./*from w  ww. j  a  v a  2 s  . com*/
 */
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();
}

From source file:org.apereo.portal.jdbc.DatabaseMetaDataImpl.java

/**
 * Gets meta data about the connection./*from   ww w. j a v a2s  .  c o m*/
 */
private void getMetaData(final Connection conn) {
    try {
        final DatabaseMetaData dmd = conn.getMetaData();

        this.databaseProductName = dmd.getDatabaseProductName();
        this.databaseProductVersion = dmd.getDatabaseProductVersion();
        this.driverName = dmd.getDriverName();
        this.driverVersion = dmd.getDriverVersion();
        this.userName = dmd.getUserName();
        this.dbUrl = dmd.getURL();
        this.dbmdSupportsOuterJoins = dmd.supportsOuterJoins();
    } catch (SQLException sqle) {
        LOG.error("Error getting database meta data.", sqle);
    }
}

From source file:org.artifactory.storage.db.DbServiceImpl.java

private void printConnectionInfo() throws SQLException {
    Connection connection = jdbcHelper.getDataSource().getConnection();
    try {//from  ww w . j  av a 2s  .c  o m
        DatabaseMetaData meta = connection.getMetaData();
        log.info("Database: {} {}. Driver: {} {}", meta.getDatabaseProductName(),
                meta.getDatabaseProductVersion(), meta.getDriverName(), meta.getDriverVersion());
        log.info("Connection URL: {}", meta.getURL());
    } catch (SQLException e) {
        log.warn("Can not retrieve database and driver name / version", e);
    } finally {
        DbUtils.close(connection);
    }
}

From source file:org.beangle.webapp.database.action.DatasourceAction.java

public String test() {
    Long datasourceId = getEntityId("datasource");
    DataSource dataSource = datasourceService.getDatasource(datasourceId);
    Map<String, String> driverinfo = CollectUtils.newHashMap();
    Map<String, Object> dbinfo = CollectUtils.newHashMap();
    Map<String, Object> jdbcinfo = CollectUtils.newHashMap();
    Connection con = null;//from  ww  w  . java  2 s.c o  m
    try {
        con = dataSource.getConnection();
        if (con != null) {
            java.sql.DatabaseMetaData dm = con.getMetaData();
            driverinfo.put("Driver Name", dm.getDriverName());
            driverinfo.put("Driver Version", dm.getDriverVersion());
            dbinfo.put("Database Name", dm.getDatabaseProductName());
            dbinfo.put("Database Version", dm.getDatabaseProductVersion());
            jdbcinfo.put("JDBC Version", dm.getJDBCMajorVersion() + "." + dm.getJDBCMinorVersion());
            StringBuilder catelogs = new StringBuilder();
            dbinfo.put("Avalilable Catalogs", catelogs);
            java.sql.ResultSet rs = dm.getCatalogs();
            while (rs.next()) {
                catelogs.append(rs.getString(1));
                if (rs.next())
                    catelogs.append(',');
            }
            rs.close();
        }
    } catch (Exception e) {
        put("exceptionStack", ExceptionUtils.getFullStackTrace(e));
    } finally {
        try {
            if (con != null)
                con.close();
            con = null;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    put("driverinfo", driverinfo);
    put("dbinfo", dbinfo);
    put("jdbcinfo", jdbcinfo);
    return forward();
}