Example usage for java.sql DatabaseMetaData getDatabaseMinorVersion

List of usage examples for java.sql DatabaseMetaData getDatabaseMinorVersion

Introduction

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

Prototype

int getDatabaseMinorVersion() throws SQLException;

Source Link

Document

Retrieves the minor version number of the underlying database.

Usage

From source file:annis.administration.AbstractAdminstrationDao.java

/**
 * Closes all open idle connections. The current data source
 * must have superuser rights./*w w  w . ja  va  2 s .  c o m*/
 * 
 * This can be used if a another database action needs full access to a database,
 * e.g. when deleting and then creating it
 * @param databasename
 */
protected void closeAllConnections(String databasename) {
    String sql = "SELECT pg_terminate_backend(pg_stat_activity.pid)\n" + "FROM pg_stat_activity\n"
            + "WHERE pg_stat_activity.datname = ?\n" + "  AND pid <> pg_backend_pid();";
    try (Connection conn = getDataSource().getConnection()) {
        DatabaseMetaData meta = conn.getMetaData();

        if (meta.getDatabaseMajorVersion() == 9 && meta.getDatabaseMinorVersion() <= 1) {
            sql = "SELECT pg_terminate_backend(pg_stat_activity.procpid)\n" + "FROM pg_stat_activity\n"
                    + "WHERE pg_stat_activity.datname = ?\n" + "  AND procpid <> pg_backend_pid();";
        }
    } catch (SQLException ex) {
        log.warn("Could not get the PostgreSQL version", ex);
    }

    getJdbcTemplate().queryForRowSet(sql, databasename);

}

From source file:it.greenvulcano.gvesb.j2ee.db.connections.impl.DriverPoolConnectionBuilder.java

public Connection getConnection() throws GVDBException {
    try {/*from   w  ww.  ja  va 2  s .  c o  m*/
        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:net.risesoft.soa.asf.web.controller.SystemController.java

private List<SysInfo> getDBInfo() {
    List list = new ArrayList();
    String group = "4. ??";
    try {/*from ww  w. j  av  a 2 s.  c  om*/
        Connection conn = this.basicDataSource.getConnection();
        try {
            DatabaseMetaData dbmd = conn.getMetaData();
            list.add(new SysInfo("DatabaseProductName", dbmd.getDatabaseProductName(), group));
            list.add(new SysInfo("DatabaseProductVersion", dbmd.getDatabaseProductVersion(), group));
            list.add(new SysInfo("DatabaseMajorVersion", Integer.valueOf(dbmd.getDatabaseMajorVersion()),
                    group));
            list.add(new SysInfo("DatabaseMinorVersion", Integer.valueOf(dbmd.getDatabaseMinorVersion()),
                    group));
            list.add(new SysInfo("DriverName", dbmd.getDriverName(), group));
            list.add(new SysInfo("DriverVersion", dbmd.getDriverVersion(), group));
            list.add(new SysInfo("DriverMajorVersion", Integer.valueOf(dbmd.getDriverMajorVersion()), group));
            list.add(new SysInfo("DriverMinorVersion", Integer.valueOf(dbmd.getDriverMinorVersion()), group));
        } finally {
            conn.close();
        }
        group = "5. ?";
        BasicDataSource bds = this.basicDataSource;
        list.add(new SysInfo("InitialSize", Integer.valueOf(bds.getInitialSize()), group));
        list.add(new SysInfo("MaxActive", Integer.valueOf(bds.getMaxActive()), group));
        list.add(new SysInfo("MaxIdle", Integer.valueOf(bds.getMaxIdle()), group));
        list.add(new SysInfo("MinIdle", Integer.valueOf(bds.getMinIdle()), group));
        list.add(new SysInfo("MaxWait", Long.valueOf(bds.getMaxWait()), group));
        list.add(new SysInfo("NumActive", Integer.valueOf(bds.getNumActive()), group));
        list.add(new SysInfo("NumIdle", Integer.valueOf(bds.getNumIdle()), group));
        list.add(new SysInfo("DriverClass", bds.getDriverClassName(), group));
        list.add(new SysInfo("URL", bds.getUrl(), group));
        list.add(new SysInfo("Username", bds.getUsername(), group));
        list.add(new SysInfo("Password", "******", group));
    } catch (Exception ex) {
        log.warn("???: " + ex.getMessage(), ex);
    }
    return list;
}

From source file:com.manydesigns.portofino.model.database.ConnectionProvider.java

public void init(DatabasePlatformsRegistry databasePlatformsRegistry) {
    Connection conn = null;/* w w  w  .  ja  va 2s .c  om*/
    ResultSet typeRs = null;
    String databaseName = getDatabase().getDatabaseName();
    try {
        conn = acquireConnection();

        DatabaseMetaData metadata = conn.getMetaData();

        databaseProductName = metadata.getDatabaseProductName();
        databaseProductVersion = metadata.getDatabaseProductVersion();

        try {
            databaseMajorVersion = metadata.getDatabaseMajorVersion();
            databaseMinorVersion = metadata.getDatabaseMinorVersion();
            databaseMajorMinorVersion = MessageFormat.format("{0}.{1}", databaseMajorVersion,
                    databaseMinorVersion);
        } catch (SQLException e) {
            databaseMajorMinorVersion = e.getMessage();
        }

        driverName = metadata.getDriverName();
        driverVersion = metadata.getDriverVersion();

        driverMajorVersion = metadata.getDriverMajorVersion();
        driverMinorVersion = metadata.getDriverMinorVersion();
        driverMajorMinorVersion = MessageFormat.format("{0}.{1}", driverMajorVersion, driverMinorVersion);

        try {
            JDBCMajorVersion = metadata.getJDBCMajorVersion();
            JDBCMinorVersion = metadata.getJDBCMinorVersion();
            JDBCMajorMinorVersion = MessageFormat.format("{0}.{1}", JDBCMajorVersion, JDBCMinorVersion);
        } catch (Throwable e) {
            JDBCMajorMinorVersion = e.getMessage();
        }

        // extract supported types
        types.clear();
        typeRs = metadata.getTypeInfo();
        while (typeRs.next()) {
            readType(typeRs);
        }
        fixMissingTypeAliases(types);
        Collections.sort(types, new TypeComparator());

        databasePlatform = databasePlatformsRegistry.findApplicableAbstraction(this);
        if (databasePlatform == null) {
            status = STATUS_ERROR;
            errorMessage = MessageFormat.format("Database platform not found for {0}", databaseProductName);
            logger.warn(errorMessage);
        } else {
            status = STATUS_CONNECTED;
            errorMessage = null;
        }
    } catch (Throwable e) {
        status = STATUS_ERROR;
        errorMessage = e.getMessage();
        logger.warn("Could not create database platform for " + databaseName, e);
    } finally {
        DbUtil.closeResultSetAndStatement(typeRs);
        releaseConnection(conn);
        lastTested = new Date();
    }
}

From source file:net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.java

/**
 * /* ww  w . j a  v  a2  s. c o m*/
 */
public JRJdbcQueryExecuter(JasperReportsContext jasperReportsContext, JRDataset dataset,
        Map<String, ? extends JRValueParameter> parameters) {
    super(jasperReportsContext, dataset, parameters);

    connection = (Connection) getParameterValue(JRParameter.REPORT_CONNECTION);
    if (connection == null) {
        if (log.isWarnEnabled()) {
            log.warn("The supplied java.sql.Connection object is null.");
        }
    } else if (log.isDebugEnabled()) {
        try {
            DatabaseMetaData metaData = connection.getMetaData();
            log.debug("DB is " + metaData.getDatabaseProductName() + " version "
                    + metaData.getDatabaseProductVersion() + " (" + metaData.getDatabaseMajorVersion() + "/"
                    + metaData.getDatabaseMinorVersion() + ")");
            log.debug("driver is " + metaData.getDriverName() + " version " + metaData.getDriverVersion() + " ("
                    + metaData.getDriverMajorVersion() + "/" + metaData.getDriverMinorVersion() + ")");
            log.debug("jdbc " + metaData.getJDBCMajorVersion() + "/" + metaData.getJDBCMinorVersion());
            log.debug("connection URL is " + metaData.getURL());
        } catch (SQLException e) {
            log.debug("failed to read connection metadata", e);
        }
    }

    isCachedRowSet = getBooleanParameterOrProperty(JRJdbcQueryExecuterFactory.PROPERTY_CACHED_ROWSET, false);

    setTimeZone();

    registerFunctions();

    parseQuery();
}

From source file:com.jaxio.celerio.configuration.database.support.MetadataExtractor.java

private DatabaseInfo extractDatabaseInfo(DatabaseMetaData databaseMetaData) {
    DatabaseInfo database = new DatabaseInfo();

    // database//from  w ww . j  av a2 s . co m
    try {
        database.setDatabaseProductName(databaseMetaData.getDatabaseProductName());
    } catch (Exception e) { /* ignore */
    }

    try {
        database.setDatabaseProductVersion(databaseMetaData.getDatabaseProductVersion());
    } catch (Exception e) { /* ignore */
    }

    try {
        database.setDatabaseMajorVersion(databaseMetaData.getDatabaseMajorVersion());
    } catch (Exception e) { /* ignore */
    }

    try {
        database.setDatabaseMinorVersion(databaseMetaData.getDatabaseMinorVersion());
    } catch (Exception e) { /* ignore */
    }

    // driver
    try {
        database.setDriverName(databaseMetaData.getDriverName());
    } catch (Exception e) { /* ignore */
    }

    try {
        database.setDriverVersion(databaseMetaData.getDriverVersion());
    } catch (Exception e) { /* ignore */
    }

    try {
        database.setDriverMajorVersion(databaseMetaData.getDriverMajorVersion());
    } catch (Exception e) { /* ignore */
    }

    try {
        database.setDriverMinorVersion(databaseMetaData.getDriverMinorVersion());
    } catch (Exception e) { /* ignore */
    }

    return database;
}

From source file:annis.dao.SpringAnnisDao.java

@Override
public boolean checkDatabaseVersion() throws AnnisException {
    try (Connection conn = getJdbcTemplate().getDataSource().getConnection();) {

        DatabaseMetaData meta = conn.getMetaData();

        log.debug("database info [major: " + meta.getDatabaseMajorVersion() + " minor: "
                + meta.getDatabaseMinorVersion() + " complete: " + meta.getDatabaseProductVersion() + " name: "
                + meta.getDatabaseProductName() + "]");

        if (!"PostgreSQL".equalsIgnoreCase(meta.getDatabaseProductName())) {
            throw new AnnisException("You did provide a database connection to a "
                    + "database that is not PostgreSQL. Please note that this will " + "not work.");
        }//ww  w.  ja  v  a  2s .  co m
        if (meta.getDatabaseMajorVersion() < 9
                || (meta.getDatabaseMajorVersion() == 9 && meta.getDatabaseMinorVersion() < 1)) // we urge people to use 9.2, but 9.1 should be valid as well
        {
            throw new AnnisException("Wrong PostgreSQL version installed. Please "
                    + "install at least PostgreSQL 9.2 (current installed version is "
                    + meta.getDatabaseProductVersion() + ")");
        }
    } catch (SQLException ex) {
        log.error("could not get database version", ex);
    }

    return false;
}

From source file:net.hydromatic.optiq.test.JdbcTest.java

/**
 * Make sure that the properties look sane.
 *//*from  w w w  .  ja  v  a  2  s.  c  o m*/
@Test
public void testVersion() throws ClassNotFoundException, SQLException {
    Class.forName("net.hydromatic.optiq.jdbc.Driver");
    Connection connection = DriverManager.getConnection("jdbc:optiq:");
    OptiqConnection optiqConnection = connection.unwrap(OptiqConnection.class);
    final DatabaseMetaData metaData = optiqConnection.getMetaData();
    assertEquals("Optiq JDBC Driver", metaData.getDriverName());

    final String driverVersion = metaData.getDriverVersion();
    final int driverMajorVersion = metaData.getDriverMajorVersion();
    final int driverMinorVersion = metaData.getDriverMinorVersion();
    assertEquals(0, driverMajorVersion);
    assertEquals(4, driverMinorVersion);

    assertEquals("Optiq", metaData.getDatabaseProductName());
    final String databaseProductVersion = metaData.getDatabaseProductVersion();
    final int databaseMajorVersion = metaData.getDatabaseMajorVersion();
    assertEquals(driverMajorVersion, databaseMajorVersion);
    final int databaseMinorVersion = metaData.getDatabaseMinorVersion();
    assertEquals(driverMinorVersion, databaseMinorVersion);

    // Check how version is composed of major and minor version. Note that
    // version is stored in pom.xml; major and minor version are
    // stored in net-hydromatic-optiq-jdbc.properties.
    if (!driverVersion.endsWith("-SNAPSHOT")) {
        assertTrue(driverVersion.startsWith("0."));
        String[] split = driverVersion.split("\\.");
        assertTrue(split.length >= 2);
        assertTrue(driverVersion.startsWith(driverMajorVersion + "." + driverMinorVersion + "."));
    }
    if (!databaseProductVersion.endsWith("-SNAPSHOT")) {
        assertTrue(databaseProductVersion.startsWith("0."));
        String[] split = databaseProductVersion.split("\\.");
        assertTrue(split.length >= 2);
        assertTrue(databaseProductVersion.startsWith(databaseMajorVersion + "." + databaseMinorVersion + "."));
    }

    connection.close();
}

From source file:com.hangum.tadpole.engine.manager.TadpoleSQLManager.java

/**
 * ? DB? metadata ?./*w w w .  j a v  a 2s  .c  o m*/
 * 
 * @param searchKey
 * @param userDB
 * @param dbMetadata
 * @return
 */
public static void setMetaData(String searchKey, final UserDBDAO userDB, DatabaseMetaData dbMetaData)
        throws Exception {
    //  ??  .
    if (userDB.getDBDefine() == DBDefine.TADPOLE_SYSTEM_DEFAULT
            || userDB.getDBDefine() == DBDefine.TADPOLE_SYSTEM_MYSQL_DEFAULT)
        return;

    String strIdentifierQuoteString = "";
    try {
        strIdentifierQuoteString = dbMetaData.getIdentifierQuoteString();
    } catch (Exception e) {
        // ignore exception, not support quoteString
    }

    // https://github.com/hangum/TadpoleForDBTools/issues/412 ? ??  .
    TadpoleMetaData tadpoleMetaData = null;
    switch (userDB.getDBDefine()) {
    case ORACLE_DEFAULT:
    case TIBERO_DEFAULT:
        tadpoleMetaData = new TadpoleMetaData(strIdentifierQuoteString,
                TadpoleMetaData.STORES_FIELD_TYPE.LOWCASE_BLANK);
        break;
    case MSSQL_DEFAULT:
    case MSSQL_8_LE_DEFAULT:
    case MYSQL_DEFAULT:
    case MARIADB_DEFAULT:
    case SQLite_DEFAULT:
        tadpoleMetaData = new TadpoleMetaData(strIdentifierQuoteString,
                TadpoleMetaData.STORES_FIELD_TYPE.BLANK);
        break;
    case POSTGRE_DEFAULT:
    case TAJO_DEFAULT:
        tadpoleMetaData = new TadpoleMetaData(strIdentifierQuoteString,
                TadpoleMetaData.STORES_FIELD_TYPE.UPPERCASE_BLANK);
        break;
    default:
        tadpoleMetaData = new TadpoleMetaData(strIdentifierQuoteString, TadpoleMetaData.STORES_FIELD_TYPE.NONE);
    }

    //      SQLConstantFactory factory = new SQLConstantFactory();
    //      SQLConstants sqlConstants = factory.getDB(userDB);
    //      tmd.setKeywords(
    //            StringUtils.replace(
    //                  sqlConstants.keyword() + "|" + sqlConstants.function() + "|" + sqlConstants.constant() + "|" +sqlConstants.variable(),
    //                  "|",
    //                  ","
    //                  )
    //            );
    // set keyword
    if (userDB.getDBDefine() == DBDefine.SQLite_DEFAULT) {
        // not support keyword http://sqlite.org/lang_keywords.html
        tadpoleMetaData.setKeywords(StringUtils.join(SQLConstants.QUOTE_SQLITE_KEYWORDS, ","));
    } else if (userDB.getDBDefine() == DBDefine.MYSQL_DEFAULT | userDB.getDBDefine() == DBDefine.MYSQL_DEFAULT
            | userDB.getDBDefine() == DBDefine.ORACLE_DEFAULT
            | userDB.getDBDefine() == DBDefine.TIBERO_DEFAULT) {
        String strFullKeywords = StringUtils.join(SQLConstants.QUOTE_MYSQL_KEYWORDS, ",") + "," + dbMetadata;
        tadpoleMetaData.setKeywords(strFullKeywords);
    } else if (userDB.getDBDefine() == DBDefine.MONGODB_DEFAULT) {
        // not support this method
        tadpoleMetaData.setKeywords("");
    } else if (userDB.getDBDefine() == DBDefine.MSSQL_8_LE_DEFAULT
            || userDB.getDBDefine() == DBDefine.MSSQL_DEFAULT) {
        String strFullKeywords = StringUtils.join(SQLConstants.QUOTE_MSSQL_KEYWORDS, ",") + ","
                + dbMetaData.getSQLKeywords();
        tadpoleMetaData.setKeywords(strFullKeywords);
    } else {
        tadpoleMetaData.setKeywords(dbMetaData.getSQLKeywords());
    }

    tadpoleMetaData.setDbMajorVersion(dbMetaData.getDatabaseMajorVersion());
    tadpoleMetaData.setMinorVersion(dbMetaData.getDatabaseMinorVersion());
    dbMetadata.put(searchKey, tadpoleMetaData);
}

From source file:jef.database.DbMetaData.java

/**
 * ??//www .j a va 2 s.  c  o  m
 * 
 * @return Map<String,String> [key] is
 *         <ul>
 *         <li>DatabaseProductName</li>
 *         <li>DatabaseProductVersion</li>
 *         <li>DriverName</li>
 *         <li>DriverVersion</li>
 *         </ul>
 */
public Map<String, String> getDbVersion() throws SQLException {
    Connection conn = getConnection(false);
    DatabaseMetaData databaseMetaData = conn.getMetaData();
    Map<String, String> map = new SimpleMap<String, String>();
    map.put("DriverName", databaseMetaData.getDriverName());
    map.put("DriverVersion",
            databaseMetaData.getDriverVersion() + " " + databaseMetaData.getDatabaseMinorVersion());
    map.put("DatabaseProductName", databaseMetaData.getDatabaseProductName());
    map.put("DatabaseProductVersion",
            databaseMetaData.getDatabaseProductVersion() + " " + databaseMetaData.getDatabaseMinorVersion());

    String otherVersionSQL = info.profile.getProperty(DbProperty.OTHER_VERSION_SQL);
    if (otherVersionSQL != null) {
        for (String sql : StringUtils.split(otherVersionSQL, ";")) {
            if (StringUtils.isBlank(sql))
                continue;
            Statement st = conn.createStatement();
            ResultSet rs = null;
            try {
                rs = st.executeQuery(sql);
                while (rs.next()) {
                    map.put(rs.getString(1), rs.getString(2));
                }
            } finally {
                DbUtils.close(rs);
                DbUtils.close(st);
            }
        }
    }
    releaseConnection(conn);
    return map;
}