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:Main.java

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

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

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

From source file:Main.java

public static void main(String[] args) throws Exception {
    Class.forName(DRIVER);/*from  www. j  a  v a2  s .  c  om*/
    Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);

    DatabaseMetaData metadata = connection.getMetaData();

    int majorVersion = metadata.getDatabaseMajorVersion();
    System.out.println("majorVersion = " + majorVersion);

    int minorVersion = metadata.getDatabaseMinorVersion();
    System.out.println("minorVersion = " + minorVersion);

    String productName = metadata.getDatabaseProductName();
    System.out.println("productName = " + productName);

    String productVersion = metadata.getDatabaseProductVersion();
    System.out.println("productVersion = " + productVersion);
    connection.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getMySqlConnection();
    DatabaseMetaData meta = conn.getMetaData();
    try {/*from   w w  w.  j  a  v a 2 s .c o  m*/
        int majorVersion = meta.getDatabaseMajorVersion();
        System.out.println("major Version: " + majorVersion);
        int minorVersion = meta.getDatabaseMinorVersion();
        System.out.println("minorVersion" + minorVersion);
    } catch (Exception e) {
        System.out.println("minorVersion unsupported feature");
    }

    String productName = meta.getDatabaseProductName();
    String productVersion = meta.getDatabaseProductVersion();
    System.out.println("productName" + productName);
    System.out.println("productVersion" + productVersion);
    conn.close();
}

From source file:Main.java

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

    DatabaseMetaData meta = conn.getMetaData();
    try {/*from   w ww  .  java2 s .  c  o m*/
        int majorVersion = meta.getDatabaseMajorVersion();
        System.out.println("major Version:" + majorVersion);
    } catch (Exception e) {
        System.out.println("major Version:unsupported feature");
    }

    try {
        int minorVersion = meta.getDatabaseMinorVersion();
        System.out.println("minorVersion:" + minorVersion);
    } catch (Exception e) {
        System.out.println("minorVersion unsupported feature");
    }

    conn.close();
}

From source file:TestDatabaseMetaDataToolDatabaseInformation.java

public static void main(String[] args) throws Exception {
    Connection conn = getMySqlConnection();
    DatabaseMetaData meta = conn.getMetaData();
    // Oracle (and some other vendors) do not support
    // some the following methods; therefore, we need
    // to use try-catch block.
    try {//from   ww  w  .j av  a 2s  . c  om
        int majorVersion = meta.getDatabaseMajorVersion();
        System.out.println("major Version: " + majorVersion);
    } catch (Exception e) {
        System.out.println("major Version: unsupported feature");
    }

    try {
        int minorVersion = meta.getDatabaseMinorVersion();
        System.out.println("minorVersion" + minorVersion);
    } catch (Exception e) {
        System.out.println("minorVersion unsupported feature");
    }

    String productName = meta.getDatabaseProductName();
    String productVersion = meta.getDatabaseProductVersion();
    System.out.println("productName" + productName);
    System.out.println("productVersion" + productVersion);
    conn.close();
}

From source file:com.aionemu.commons.database.DatabaseFactory.java

public synchronized static void init(String configFilePath) {
    if (dataSource != null) {
        return;/*from   w  ww  .  j  av a  2  s.c  om*/
    }

    if (!configFilePath.equals("")) {
        try {
            Properties dbProps = PropertiesUtils.load(configFilePath);
            ConfigurableProcessor.process(DatabaseConfig.class, dbProps);
        } catch (IOException ex) {
            log.fatal("Cannot load database config", ex);
        }
    }

    try {
        DatabaseConfig.DATABASE_DRIVER.newInstance();
    } catch (Exception e) {
        log.fatal("Error obtaining DB driver", e);
        throw new Error("DB Driver doesnt exist!");
    }

    connectionPool = new GenericObjectPool();

    if (DatabaseConfig.DATABASE_CONNECTIONS_MIN > DatabaseConfig.DATABASE_CONNECTIONS_MAX) {
        log.error("Please check your database configuration. Minimum amount of connections is > maximum");
        DatabaseConfig.DATABASE_CONNECTIONS_MAX = DatabaseConfig.DATABASE_CONNECTIONS_MIN;
    }

    connectionPool.setMaxIdle(DatabaseConfig.DATABASE_CONNECTIONS_MIN);
    connectionPool.setMaxActive(DatabaseConfig.DATABASE_CONNECTIONS_MAX);
    /* test if connection is still valid before returning */
    //connectionPool.setTestOnBorrow(true);

    try {
        dataSource = setupDataSource();
        Connection c = getConnection();
        DatabaseMetaData dmd = c.getMetaData();
        databaseName = dmd.getDatabaseProductName();
        databaseMajorVersion = dmd.getDatabaseMajorVersion();
        databaseMinorVersion = dmd.getDatabaseMinorVersion();
        c.close();
    } catch (Exception e) {
        log.fatal("Error with connection string: " + DatabaseConfig.DATABASE_URL, e);
        throw new Error("DatabaseFactory not initialized!");
    }

    log.info("Successfully connected to database");
}

From source file:ca.nrc.cadc.db.DBUtil.java

private static void testDS(DataSource ds, boolean keepOpen) throws SQLException {
    Connection con = null;//from   w  w  w .java  2  s  . co  m
    try {
        con = ds.getConnection();
        DatabaseMetaData meta = con.getMetaData();
        if (!log.getEffectiveLevel().equals(Level.DEBUG))
            return;
        log.debug("connected to server: " + meta.getDatabaseProductName() + " " + meta.getDatabaseMajorVersion()
                + "." + meta.getDatabaseMinorVersion() + " driver: " + meta.getDriverName() + " "
                + meta.getDriverMajorVersion() + "." + meta.getDriverMinorVersion());
    } finally {
        if (!keepOpen && con != null)
            try {
                con.close();
            } catch (Exception ignore) {
            }
    }
}

From source file:com.trackplus.ddl.DataReader.java

private static void logDatabaseMetaDataInfo(DatabaseInfo databaseInfo, Connection connection)
        throws DDLException {
    DatabaseMetaData databaseMetaData = null;
    try {/* ww w .  j a va2 s. c  o  m*/
        databaseMetaData = connection.getMetaData();
        int majorVersion = databaseMetaData.getDatabaseMajorVersion();
        int minorVersion = databaseMetaData.getDatabaseMinorVersion();
        String productName = databaseMetaData.getDatabaseProductName();
        String productVersion = databaseMetaData.getDatabaseProductVersion();
        int driverMajorVersion = databaseMetaData.getDriverMajorVersion();
        int driverMinorVersion = databaseMetaData.getDriverMinorVersion();

        LOGGER.debug("DB DRIVER=" + databaseInfo.getDriver());
        LOGGER.debug("DB URL=" + databaseInfo.getUrl());
        LOGGER.debug("DB USER=" + databaseInfo.getUser());
        String password = databaseInfo.getPassword() == null ? null
                : databaseInfo.getPassword().replaceAll(".", "*");
        LOGGER.debug("DB PASSWORD=" + password + "\n");

        LOGGER.debug("DB majorVersion=" + majorVersion);
        LOGGER.debug("DB minorVersion=" + minorVersion);
        LOGGER.debug("DB productName=" + productName);
        LOGGER.debug("DB productVersion=" + productVersion);
        LOGGER.debug("DB driverMajorVersion=" + driverMajorVersion);
        LOGGER.debug("DB driverMinorVersion=" + driverMinorVersion);
    } catch (SQLException e) {
        throw new DDLException(e.getMessage(), e);
    }
}

From source file:com.alibaba.otter.canal.example.db.dialect.AbstractDbDialect.java

public AbstractDbDialect(final JdbcTemplate jdbcTemplate, LobHandler lobHandler) {
    this.jdbcTemplate = jdbcTemplate;
    this.lobHandler = lobHandler;
    // ?transction
    this.transactionTemplate = new TransactionTemplate();
    transactionTemplate.setTransactionManager(new DataSourceTransactionManager(jdbcTemplate.getDataSource()));
    transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);

    // ??/*w  w w  . ja v  a2  s . com*/
    jdbcTemplate.execute(new ConnectionCallback() {

        public Object doInConnection(Connection c) throws SQLException, DataAccessException {
            DatabaseMetaData meta = c.getMetaData();
            databaseName = meta.getDatabaseProductName();
            databaseMajorVersion = meta.getDatabaseMajorVersion();
            databaseMinorVersion = meta.getDatabaseMinorVersion();

            return null;
        }
    });

    initTables(jdbcTemplate);
}

From source file:com.tera.common.database.factory.AbstractDatabaseFactory.java

/**
 * @param dbConfig//from   w  w w  . j a v a2s. c  o m
 * @throws Error
 */
void createConnectionPool(DatabaseConfiguration dbConfig) throws Error {
    log.info("Creating DB pool");
    connectionPool = new GenericObjectPool();
    connectionPool.setMaxIdle(dbConfig.getConnectionsIdelMax());
    connectionPool.setMinIdle(dbConfig.getConnectionsIdleMin());
    connectionPool.setMaxActive(dbConfig.getConnectionsActiveMax());
    connectionPool.setTestOnBorrow(true);

    try {
        dataSource = setupDataSource(dbConfig);
        Connection c = getConnection();
        DatabaseMetaData dmd = c.getMetaData();
        databaseName = dmd.getDatabaseProductName();
        databaseMajorVersion = dmd.getDatabaseMajorVersion();
        databaseMinorVersion = dmd.getDatabaseMinorVersion();
        c.close();
    } catch (Exception e) {
        log.error("Error with connection string: {}", dbConfig, e);
        throw new Error("DatabaseFactory not initialized!");
    }
    log.info("Successfully connected to the database");
}