Example usage for java.sql DatabaseMetaData getDriverMinorVersion

List of usage examples for java.sql DatabaseMetaData getDriverMinorVersion

Introduction

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

Prototype

int getDriverMinorVersion();

Source Link

Document

Retrieves this JDBC driver's minor version number.

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.getDriverMinorVersion());

    conn.close();//from  w  ww  .  ja v  a  2s .com
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Class.forName(DRIVER);//from  w w  w . j a  v  a  2 s  .  co  m
    Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);

    DatabaseMetaData metadata = connection.getMetaData();
    String driverName = metadata.getDriverName();
    String driverVersion = metadata.getDriverVersion();
    int majorVersion = metadata.getDriverMajorVersion();
    int minorVersion = metadata.getDriverMinorVersion();

    System.out.println("driverName = " + driverName);
    System.out.println("driverVersion = " + driverVersion);
    System.out.println("majorVersion = " + majorVersion);
    System.out.println("minorVersion = " + minorVersion);
    connection.close();
}

From source file:Main.java

public static void main(String[] argv) {
    Connection connection = null;
    Statement statement;// w ww .  java2s  .  c  o  m
    ResultSet rs;
    try {
        Context ctx = new InitialContext();
        DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/AccountsDB");
        connection = ds.getConnection();

        DatabaseMetaData md = connection.getMetaData();
        statement = connection.createStatement();

        System.out.println("getURL() - " + md.getURL());
        System.out.println("getUserName() - " + md.getUserName());
        System.out.println("getDatabaseProductVersion - " + md.getDatabaseProductVersion());
        System.out.println("getDriverMajorVersion - " + md.getDriverMajorVersion());
        System.out.println("getDriverMinorVersion - " + md.getDriverMinorVersion());
        System.out.println("nullAreSortedHigh - " + md.nullsAreSortedHigh());

        System.out.println("<H1>Feature Support</H1>");
        System.out.println(
                "supportsAlterTableWithDropColumn - " + md.supportsAlterTableWithDropColumn() + "<BR>");
        System.out.println("supportsBatchUpdates - " + md.supportsBatchUpdates());
        System.out.println("supportsTableCorrelationNames - " + md.supportsTableCorrelationNames());
        System.out.println("supportsPositionedDelete - " + md.supportsPositionedDelete());
        System.out.println("supportsFullOuterJoins - " + md.supportsFullOuterJoins());
        System.out.println("supportsStoredProcedures - " + md.supportsStoredProcedures());
        System.out.println("supportsMixedCaseQuotedIdentifiers - " + md.supportsMixedCaseQuotedIdentifiers());
        System.out.println("supportsANSI92EntryLevelSQL - " + md.supportsANSI92EntryLevelSQL());
        System.out.println("supportsCoreSQLGrammar - " + md.supportsCoreSQLGrammar());
        System.out.println("getMaxRowSize - " + md.getMaxRowSize());
        System.out.println("getMaxStatementLength - " + md.getMaxStatementLength());
        System.out.println("getMaxTablesInSelect - " + md.getMaxTablesInSelect());
        System.out.println("getMaxConnections - " + md.getMaxConnections());
        System.out.println("getMaxCharLiteralLength - " + md.getMaxCharLiteralLength());

        System.out.println("getTableTypes()");
        rs = md.getTableTypes();
        while (rs.next()) {
            System.out.println(rs.getString(1));
        }
        System.out.println("getTables()");
        rs = md.getTables("accounts", "", "%", new String[0]);
        while (rs.next()) {
            System.out.println(rs.getString("TABLE_NAME"));
        }
        System.out.println("Transaction Support");
        System.out.println("getDefaultTransactionIsolation() - " + md.getDefaultTransactionIsolation());
        System.out
                .println("dataDefinitionIgnoredInTransactions() - " + md.dataDefinitionIgnoredInTransactions());

        System.out.println("General Source Information");
        System.out.println("getMaxTablesInSelect - " + md.getMaxTablesInSelect());
        System.out.println("getMaxColumnsInTable - " + md.getMaxColumnsInTable());
        System.out.println("getTimeDateFunctions - " + md.getTimeDateFunctions());
        System.out.println("supportsCoreSQLGrammar - " + md.supportsCoreSQLGrammar());

        System.out.println("getTypeInfo()");
        rs = md.getTypeInfo();
        while (rs.next()) {
            System.out.println(rs.getString(1));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

private static void testDS(DataSource ds, boolean keepOpen) throws SQLException {
    Connection con = null;// w w  w .  ja v  a 2s .  c  o  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 {/*  www. j ava  2 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:DatabaseInfo.java

public void doGet(HttpServletRequest inRequest, HttpServletResponse outResponse)
        throws ServletException, IOException {

    PrintWriter out = null;// w ww  .  j a va2 s.co m
    Connection connection = null;
    Statement statement;
    ResultSet rs;

    outResponse.setContentType("text/html");
    out = outResponse.getWriter();

    try {
        Context ctx = new InitialContext();
        DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/AccountsDB");
        connection = ds.getConnection();

        DatabaseMetaData md = connection.getMetaData();
        statement = connection.createStatement();

        out.println("<HTML><HEAD><TITLE>Database Server Information</TITLE></HEAD>");
        out.println("<BODY>");
        out.println("<H1>General Source Information</H1>");
        out.println("getURL() - " + md.getURL() + "<BR>");
        out.println("getUserName() - " + md.getUserName() + "<BR>");
        out.println("getDatabaseProductVersion - " + md.getDatabaseProductVersion() + "<BR>");
        out.println("getDriverMajorVersion - " + md.getDriverMajorVersion() + "<BR>");
        out.println("getDriverMinorVersion - " + md.getDriverMinorVersion() + "<BR>");
        out.println("nullAreSortedHigh - " + md.nullsAreSortedHigh() + "<BR>");

        out.println("<H1>Feature Support</H1>");
        out.println("supportsAlterTableWithDropColumn - " + md.supportsAlterTableWithDropColumn() + "<BR>");
        out.println("supportsBatchUpdates - " + md.supportsBatchUpdates() + "<BR>");
        out.println("supportsTableCorrelationNames - " + md.supportsTableCorrelationNames() + "<BR>");
        out.println("supportsPositionedDelete - " + md.supportsPositionedDelete() + "<BR>");
        out.println("supportsFullOuterJoins - " + md.supportsFullOuterJoins() + "<BR>");
        out.println("supportsStoredProcedures - " + md.supportsStoredProcedures() + "<BR>");
        out.println("supportsMixedCaseQuotedIdentifiers - " + md.supportsMixedCaseQuotedIdentifiers() + "<BR>");
        out.println("supportsANSI92EntryLevelSQL - " + md.supportsANSI92EntryLevelSQL() + "<BR>");
        out.println("supportsCoreSQLGrammar - " + md.supportsCoreSQLGrammar() + "<BR>");

        out.println("<H1>Data Source Limits</H1>");
        out.println("getMaxRowSize - " + md.getMaxRowSize() + "<BR>");
        out.println("getMaxStatementLength - " + md.getMaxStatementLength() + "<BR>");
        out.println("getMaxTablesInSelect - " + md.getMaxTablesInSelect() + "<BR>");
        out.println("getMaxConnections - " + md.getMaxConnections() + "<BR>");
        out.println("getMaxCharLiteralLength - " + md.getMaxCharLiteralLength() + "<BR>");

        out.println("<H1>SQL Object Available</H1>");
        out.println("getTableTypes()<BR><UL>");
        rs = md.getTableTypes();
        while (rs.next()) {
            out.println("<LI>" + rs.getString(1));
        }
        out.println("</UL>");

        out.println("getTables()<BR><UL>");
        rs = md.getTables("accounts", "", "%", new String[0]);
        while (rs.next()) {
            out.println("<LI>" + rs.getString("TABLE_NAME"));
        }
        out.println("</UL>");

        out.println("<H1>Transaction Support</H1>");
        out.println("getDefaultTransactionIsolation() - " + md.getDefaultTransactionIsolation() + "<BR>");
        out.println(
                "dataDefinitionIgnoredInTransactions() - " + md.dataDefinitionIgnoredInTransactions() + "<BR>");

        out.println("<H1>General Source Information</H1>");
        out.println("getMaxTablesInSelect - " + md.getMaxTablesInSelect() + "<BR>");
        out.println("getMaxColumnsInTable - " + md.getMaxColumnsInTable() + "<BR>");
        out.println("getTimeDateFunctions - " + md.getTimeDateFunctions() + "<BR>");
        out.println("supportsCoreSQLGrammar - " + md.supportsCoreSQLGrammar() + "<BR>");

        out.println("getTypeInfo()<BR><UL>");
        rs = md.getTypeInfo();
        while (rs.next()) {
            out.println("<LI>" + rs.getString(1));
        }
        out.println("</UL>");

        out.println("</BODY></HTML>");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

public Connection getConnection() throws GVDBException {
    try {/*  w  w  w .java 2  s . co 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  w w  w  .  j a  va2s .c o m*/
        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  ww .  j a  va 2 s .  c o m
    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

/**
 * /*from w  w w  .j  av  a 2 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();
}