Example usage for java.sql DatabaseMetaData getDatabaseProductVersion

List of usage examples for java.sql DatabaseMetaData getDatabaseProductVersion

Introduction

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

Prototype

String getDatabaseProductVersion() throws SQLException;

Source Link

Document

Retrieves the version number of this database product.

Usage

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 w w w . jav  a  2s. co 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();
}

From source file:org.openrdf.sail.rdbms.RdbmsStore.java

private RdbmsConnectionFactory newFactory(DatabaseMetaData metaData) throws SQLException {
    String dbn = metaData.getDatabaseProductName();
    String dbv = metaData.getDatabaseProductVersion();
    RdbmsConnectionFactory factory;//w w w.j a v a 2  s .  co  m
    Iterator<RdbmsProvider> providers;
    providers = ServiceRegistry.lookupProviders(RdbmsProvider.class);
    while (providers.hasNext()) {
        RdbmsProvider provider = providers.next();
        factory = provider.createRdbmsConnectionFactory(dbn, dbv);
        if (factory != null)
            return factory;
    }
    return new RdbmsConnectionFactory();
}

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

private void printConnectionInfo() throws SQLException {
    Connection connection = jdbcHelper.getDataSource().getConnection();
    try {//w w  w .  j  av  a 2  s .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:it.greenvulcano.gvesb.j2ee.db.connections.impl.DriverPoolConnectionBuilder.java

public Connection getConnection() throws GVDBException {
    try {/*from  www. j a  v a 2 s.c om*/
        Connection conn = dataSource.getConnection();
        if (debugJDBCConn) {
            logger.debug("Created JDBC Connection [" + name + "]: [" + conn + "]");
            if (isFirst) {
                isFirst = false;
                DatabaseMetaData dbmd = conn.getMetaData();

                logger.debug("=====  Database info =====");
                logger.debug("DatabaseProductName: " + dbmd.getDatabaseProductName());
                logger.debug("DatabaseProductVersion: " + dbmd.getDatabaseProductVersion());
                logger.debug("DatabaseMajorVersion: " + dbmd.getDatabaseMajorVersion());
                logger.debug("DatabaseMinorVersion: " + dbmd.getDatabaseMinorVersion());
                logger.debug("=====  Driver info =====");
                logger.debug("DriverName: " + dbmd.getDriverName());
                logger.debug("DriverVersion: " + dbmd.getDriverVersion());
                logger.debug("DriverMajorVersion: " + dbmd.getDriverMajorVersion());
                logger.debug("DriverMinorVersion: " + dbmd.getDriverMinorVersion());
                logger.debug("=====  JDBC/DB attributes =====");
                if (dbmd.supportsGetGeneratedKeys())
                    logger.debug("Supports getGeneratedKeys(): true");
                else
                    logger.debug("Supports getGeneratedKeys(): false");
            }
        }

        return conn;
    } catch (Exception exc) {
        throw new GVDBException("DriverPoolConnectionBuilder - Error while creating Connection[" + name + "]",
                exc);
    }
}

From source file:binky.reportrunner.service.impl.DatasourceServiceImpl.java

@Override
public String testDataSource(RunnerDataSource runnerDs) {

    try {/*from   w  w  w  . ja v  a  2  s .c o  m*/
        //fix for issue 105 - when not editing password but just testing
        if (runnerDs.getPassword() == null || runnerDs.getPassword().trim().isEmpty()) {
            // see if ds already exists but we are hiding the password
            RunnerDataSource pwget = this.dataSourceDao.get(runnerDs.getDataSourceName());
            if (pwget != null) {
                logger.debug("supplied password was blank - using stored password (if any)");
                runnerDs.setPassword(pwget.getPassword());
            }
        } else {
            EncryptionUtil enc = new EncryptionUtil();
            runnerDs.setPassword(enc.encrpyt(this.secureKey, runnerDs.getPassword()));
        }

        DataSource ds = this.getDs(runnerDs);
        Connection conn = ds.getConnection();
        DatabaseMetaData meta = conn.getMetaData();
        String information = meta.getDatabaseProductName() + ", " + meta.getDatabaseProductVersion();
        conn.close();
        if (ds instanceof BasicDataSource) {
            ((BasicDataSource) ds).close();
        }
        return information;
    } catch (Exception e) {
        if (e instanceof NullPointerException) {
            logger.fatal(e.getMessage(), e);
        }
        logger.debug(e.getMessage());
        return "ERROR - " + e.getClass().getSimpleName() + ": " + e.getMessage();
    }
}

From source file:org.dashbuilder.dataprovider.sql.SQLDataSetTestBase.java

private void printDatabaseInfo() throws Exception {
    if (!_dbInfoPrinted) {
        DatabaseMetaData meta = conn.getMetaData();
        System.out.println(/* w w  w.  ja  va2  s  .  com*/
                "\n********************************************************************************************");
        System.out.println(String.format("Database: %s %s", meta.getDatabaseProductName(),
                meta.getDatabaseProductVersion()));
        System.out.println(String.format("Driver: %s %s", meta.getDriverName(), meta.getDriverVersion()));
        System.out.println(
                "*********************************************************************************************\n");
        _dbInfoPrinted = true;
    }
}

From source file:com.netspective.axiom.connection.BasicConnectionProviderEntry.java

public void init(String dataSourceId, Connection conn) {
    this.dataSourceId = dataSourceId;

    try {//from  w w  w  . j  a v  a  2s  . c  o  m
        try {
            DatabasePolicy policy = DatabasePolicies.getInstance().getDatabasePolicy(conn);
            put(KEYNAME_DATABASE_POLICY_CLASSNAME, policy.getClass().getName());
            put(KEYNAME_DATABASE_POLICY_DBMSID, policy.getDbmsIdentifier());
        } catch (Exception dpe) {
            put(KEYNAME_DATABASE_POLICY_CLASSNAME, dpe.toString());
        }

        DatabaseMetaData dbmd = conn.getMetaData();

        put(KEYNAME_DRIVER_NAME, dbmd.getDriverName());
        put(KEYNAME_DATABASE_PRODUCT_NAME, dbmd.getDatabaseProductName());
        put(KEYNAME_DATABASE_PRODUCT_VERSION, dbmd.getDatabaseProductVersion());
        put(KEYNAME_DRIVER_VERSION, dbmd.getDriverVersion());
        put(KEYNAME_URL, dbmd.getURL());
        put(KEYNAME_USER_NAME, dbmd.getUserName());

        String resultSetType = "unknown";
        if (dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE))
            resultSetType = "scrollable (insensitive)";
        else if (dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE))
            resultSetType = "scrollable (sensitive)";
        else if (dbmd.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY))
            resultSetType = "non-scrollabe (forward only)";
        put(KEYNAME_RESULTSET_TYPE, resultSetType);

        valid = true;
    } catch (Exception e) {
        exception = e;
    } finally {
        try {
            conn.close();
        } catch (SQLException e) {
            log.error("SQL Exception while closing connection", e);
        }
    }
}

From source file:info.magnolia.about.app.AboutPresenter.java

public AboutView start() {

    // magnolia information
    LicenseFileExtractor licenseProperties = LicenseFileExtractor.getInstance();
    String mgnlEdition = getEditionName();
    String mgnlVersion = licenseProperties.get(LicenseFileExtractor.VERSION_NUMBER);
    String authorInstance = serverConfiguration.isAdmin() ? i18n.translate("about.app.main.instance.author")
            : i18n.translate("about.app.main.instance.public");

    // system information
    String osInfo = String.format("%s %s (%s)", magnoliaProperties.getProperty("os.name"),
            magnoliaProperties.getProperty("os.version"), magnoliaProperties.getProperty("os.arch"));
    String javaInfo = String.format("%s (build %s)", magnoliaProperties.getProperty("java.version"),
            magnoliaProperties.getProperty("java.runtime.version"));
    String serverInfo = MgnlContext.getWebContext().getServletContext().getServerInfo();

    String dbInfo;/*from   w  w  w.  ja v  a  2s.c  o  m*/
    String dbDriverInfo;
    Connection connection = null;
    try {

        String connectionString[] = getConnectionString();

        String repoHome = magnoliaProperties.getProperty("magnolia.repositories.home");
        String repoName = getRepoName();
        connectionString[0] = StringUtils.replace(connectionString[0], "${wsp.home}",
                repoHome + "/" + repoName + "/workspaces/default");
        connection = DriverManager.getConnection(connectionString[0], connectionString[1], connectionString[2]);
        DatabaseMetaData meta = connection.getMetaData();
        dbInfo = meta.getDatabaseProductName() + " " + meta.getDatabaseProductVersion();
        if (dbInfo.toLowerCase().indexOf("mysql") != -1) {
            String engine = getMySQLEngineInfo(connection, connectionString);
            if (engine != null) {
                dbInfo += engine;
            }
        }
        dbDriverInfo = meta.getDriverName() + " " + meta.getDriverVersion();

    } catch (SQLException e) {
        log.debug("Failed to read DB and driver info from connection with {}", e.getMessage(), e);
        dbInfo = i18n.translate("about.app.main.unknown");
        dbDriverInfo = dbInfo;
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                // ignore, nothing we can do
            }
        }
    }

    String jcrInfo;
    try {
        Repository repo = JcrUtils.getRepository();
        jcrInfo = String.format("%s %s", repo.getDescriptor("jcr.repository.name"),
                repo.getDescriptor("jcr.repository.version"));
    } catch (RepositoryException e) {
        log.debug("JCR repository information is not available", e);
        jcrInfo = "-";
    }

    // Prepare information for the view
    viewData.addItemProperty(AboutView.MAGNOLIA_EDITION_KEY, new ObjectProperty<String>(mgnlEdition));
    viewData.addItemProperty(AboutView.MAGNOLIA_VERSION_KEY, new ObjectProperty<String>(mgnlVersion));
    viewData.addItemProperty(AboutView.MAGNOLIA_INSTANCE_KEY, new ObjectProperty<String>(authorInstance));
    viewData.addItemProperty(AboutView.OS_INFO_KEY, new ObjectProperty<String>(osInfo));
    viewData.addItemProperty(AboutView.JAVA_INFO_KEY, new ObjectProperty<String>(javaInfo));
    viewData.addItemProperty(AboutView.SERVER_INFO_KEY, new ObjectProperty<String>(serverInfo));
    viewData.addItemProperty(AboutView.JCR_INFO_KEY, new ObjectProperty<String>(jcrInfo));
    viewData.addItemProperty(AboutView.DB_INFO_KEY, new ObjectProperty<String>(dbInfo));
    viewData.addItemProperty(AboutView.DB_DRIVER_INFO_KEY, new ObjectProperty<String>(dbDriverInfo));
    view.setDataSource(viewData);

    return view;
}

From source file:org.seasar.dbflute.helper.jdbc.connection.DfDataSourceHandler.java

protected void processConnectionMetaInfo(Connection conn) throws SQLException {
    if (_alreadySetupMeta) {
        return;/*from w w w. j a va2 s.  c om*/
    }
    try {
        final DfConnectionMetaInfo metaInfo = new DfConnectionMetaInfo();
        final DatabaseMetaData metaData = conn.getMetaData();
        metaInfo.setProductName(metaData.getDatabaseProductName());
        metaInfo.setProductVersion(metaData.getDatabaseProductVersion());
        metaInfo.setDriverName(metaData.getDriverName());
        metaInfo.setDriverVersion(metaData.getDriverVersion());
        final int majorVersion = metaData.getJDBCMajorVersion();
        final int minorVersion = metaData.getJDBCMinorVersion();
        metaInfo.setJdbcVersion(majorVersion + "." + minorVersion);
        _log.info("  product = " + metaInfo.getProductDisp());
        _log.info("  driver  = " + metaInfo.getDriverDisp());
        _connectionMetaInfo = metaInfo;
    } catch (SQLException continued) {
        _log.info("*Failed to get connection meta: " + continued.getMessage());
        _connectionMetaInfo = null;
    }
    _alreadySetupMeta = true;
}

From source file:org.sonar.server.telemetry.TelemetryDaemonTest.java

private void assertDatabaseMetadata(String json) {
    try (DbSession dbSession = db.getDbClient().openSession(false)) {
        DatabaseMetaData metadata = dbSession.getConnection().getMetaData();
        assertJson(json).isSimilarTo("{\n" + "  \"database\": {\n" + "    \"name\": \"H2\",\n"
                + "    \"version\": \"" + metadata.getDatabaseProductVersion() + "\"\n" + "  }\n" + "}");
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }/* w  w  w . ja  v  a2  s. c om*/
}