Example usage for java.sql DatabaseMetaData getDatabaseMajorVersion

List of usage examples for java.sql DatabaseMetaData getDatabaseMajorVersion

Introduction

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

Prototype

int getDatabaseMajorVersion() throws SQLException;

Source Link

Document

Retrieves the major version number of the underlying database.

Usage

From source file:org.wso2.extension.siddhi.store.rdbms.util.RDBMSTableUtils.java

/**
 * Utility method used for looking up DB metadata information from a given datasource.
 *
 * @param ds the datasource from which the metadata needs to be looked up.
 * @return a list of DB metadata./*www . ja va2s. co  m*/
 */
public static Map<String, Object> lookupDatabaseInfo(DataSource ds) {
    Connection conn = null;
    try {
        conn = ds.getConnection();
        DatabaseMetaData dmd = conn.getMetaData();
        Map<String, Object> result = new HashMap<>();
        result.put(DATABASE_PRODUCT_NAME, dmd.getDatabaseProductName());
        result.put(VERSION,
                Double.parseDouble(dmd.getDatabaseMajorVersion() + "." + dmd.getDatabaseMinorVersion()));
        return result;
    } catch (SQLException e) {
        throw new RDBMSTableException("Error in looking up database type: " + e.getMessage(), e);
    } finally {
        cleanupConnection(null, null, conn);
    }
}

From source file:swp.bibjsf.persistence.Data.java

/**
 * Returns the lower-case names of all tables in the database.
 *
 * @return list of lower-case names of all tables in the database
 * @throws SQLException/*from  w ww .  jav a 2 s.  c o  m*/
 *             falls ein Fehler beim Zugriff auf die Datenbank auftritt
 */
private List<String> getTableNames() throws SQLException {
    logger.debug("get table names");
    DatabaseMetaData dbMeta;
    List<String> result = new ArrayList<String>();
    Connection dbConnection = dataSource.getConnection();
    try {
        dbMeta = dbConnection.getMetaData();
        logger.debug("URL of database " + dbMeta.getURL());
        logger.debug("database version: major=" + dbMeta.getDatabaseMajorVersion() + " minor="
                + dbMeta.getDatabaseMinorVersion() + " product_version=" + dbMeta.getDatabaseProductVersion()
                + " product_name=" + dbMeta.getDatabaseProductName());

        ResultSet rs = dbMeta.getTables(null, null, null, new String[] { "TABLE" });
        try {
            while (rs.next()) {
                String theTableName = rs.getString("TABLE_NAME");
                result.add(theTableName.toLowerCase());
            }
        } finally {
            rs.close();
        }
        return result;
    } finally {
        try {
            dbConnection.close();
        } catch (SQLException e) {
            logger.debug("error while trying to close the database connection.");
            // ignore, nothing to be done here anyway
        }
    }
}