List of usage examples for java.sql DatabaseMetaData getDatabaseMinorVersion
int getDatabaseMinorVersion() throws SQLException;
From source file:jef.database.DbMetaData.java
private List<Function> innerGetFunctions(String schema, String name) throws SQLException { if (schema == null) { schema = this.schema; }// w w w.j a v a 2s. co m Connection conn = getConnection(false); DatabaseDialect profile = getProfile(); if (profile.has(Feature.NOT_SUPPORT_USER_FUNCTION)) { return Collections.emptyList(); } List<Function> result = new ArrayList<Function>(); DatabaseMetaData databaseMetaData = conn.getMetaData(); ResultSet rs = null; try { rs = databaseMetaData.getFunctions(profile.getCatlog(schema), profile.getSchema(schema), name); while (rs.next()) { Function function = new Function(); function.setCatalog(rs.getString(1)); function.setSchema(rs.getString(2)); function.setName(rs.getString(3)); function.setRemarks(rs.getString(4)); function.setType(rs.getShort(5)); function.setSpecificName(rs.getString(6)); result.add(function); } } catch (java.sql.SQLFeatureNotSupportedException e) { LogUtil.warn(databaseMetaData.getDriverName() + " doesn't supprt getFunctions() defined in JDDBC 4.0."); } catch (AbstractMethodError e) { // Driver version is too old... StringBuilder sb = new StringBuilder("The driver ").append(databaseMetaData.getDriverName()); sb.append(' ').append(databaseMetaData.getDriverVersion()).append(' ') .append(databaseMetaData.getDatabaseMinorVersion()); sb.append(" not implements JDBC 4.0, please upgrade you JDBC Driver."); throw new SQLException(sb.toString()); } finally { DbUtils.close(rs); releaseConnection(conn); } return result; }
From source file:org.acmsl.queryj.tools.handlers.DatabaseMetaDataRetrievalHandler.java
/** * Retrieves the database minor version. * @param metaData the database metadata. * @return the database minor version./*from www.jav a 2s. c om*/ */ protected int retrieveDatabaseMinorVersion(@NotNull final DatabaseMetaData metaData) { int result = -1; try { result = metaData.getDatabaseMinorVersion(); } catch (@NotNull final SQLException sqlException) { @Nullable final Log t_Log = UniqueLogFactory.getLog(DatabaseMetaDataRetrievalHandler.class); if (t_Log != null) { t_Log.debug("Cannot retrieve database vendor's minor version.", sqlException); } } return result; }
From source file:org.apache.bigtop.itest.hive.TestJdbc.java
/** * Test simple DatabaseMetaData calls. getColumns is tested elsewhere, as we need to call * that on a valid table. Same with getFunctions. * * @throws SQLException/* w w w. j a va2 s.c o m*/ */ @Test public void databaseMetaDataCalls() throws SQLException { DatabaseMetaData md = conn.getMetaData(); boolean boolrc = md.allTablesAreSelectable(); LOG.debug("All tables are selectable? " + boolrc); String strrc = md.getCatalogSeparator(); LOG.debug("Catalog separator " + strrc); strrc = md.getCatalogTerm(); LOG.debug("Catalog term " + strrc); ResultSet rs = md.getCatalogs(); while (rs.next()) { strrc = rs.getString(1); LOG.debug("Found catalog " + strrc); } Connection c = md.getConnection(); int intrc = md.getDatabaseMajorVersion(); LOG.debug("DB major version is " + intrc); intrc = md.getDatabaseMinorVersion(); LOG.debug("DB minor version is " + intrc); strrc = md.getDatabaseProductName(); LOG.debug("DB product name is " + strrc); strrc = md.getDatabaseProductVersion(); LOG.debug("DB product version is " + strrc); intrc = md.getDefaultTransactionIsolation(); LOG.debug("Default transaction isolation is " + intrc); intrc = md.getDriverMajorVersion(); LOG.debug("Driver major version is " + intrc); intrc = md.getDriverMinorVersion(); LOG.debug("Driver minor version is " + intrc); strrc = md.getDriverName(); LOG.debug("Driver name is " + strrc); strrc = md.getDriverVersion(); LOG.debug("Driver version is " + strrc); strrc = md.getExtraNameCharacters(); LOG.debug("Extra name characters is " + strrc); strrc = md.getIdentifierQuoteString(); LOG.debug("Identifier quote string is " + strrc); // In Hive 1.2 this always returns an empty RS rs = md.getImportedKeys("a", "b", "d"); // In Hive 1.2 this always returns an empty RS rs = md.getIndexInfo("a", "b", "d", true, true); intrc = md.getJDBCMajorVersion(); LOG.debug("JDBC major version is " + intrc); intrc = md.getJDBCMinorVersion(); LOG.debug("JDBC minor version is " + intrc); intrc = md.getMaxColumnNameLength(); LOG.debug("Maximum column name length is " + intrc); strrc = md.getNumericFunctions(); LOG.debug("Numeric functions are " + strrc); // In Hive 1.2 this always returns an empty RS rs = md.getPrimaryKeys("a", "b", "d"); // In Hive 1.2 this always returns an empty RS rs = md.getProcedureColumns("a", "b", "d", "e"); strrc = md.getProcedureTerm(); LOG.debug("Procedures are called " + strrc); // In Hive 1.2 this always returns an empty RS rs = md.getProcedures("a", "b", "d"); strrc = md.getSchemaTerm(); LOG.debug("Schemas are called " + strrc); rs = md.getSchemas(); while (rs.next()) { strrc = rs.getString(1); LOG.debug("Found schema " + strrc); } strrc = md.getSearchStringEscape(); LOG.debug("Search string escape is " + strrc); strrc = md.getStringFunctions(); LOG.debug("String functions are " + strrc); strrc = md.getSystemFunctions(); LOG.debug("System functions are " + strrc); rs = md.getTableTypes(); while (rs.next()) { strrc = rs.getString(1); LOG.debug("Found table type " + strrc); } strrc = md.getTimeDateFunctions(); LOG.debug("Time/date functions are " + strrc); rs = md.getTypeInfo(); while (rs.next()) { strrc = rs.getString(1); LOG.debug("Found type " + strrc); } // In Hive 1.2 this always returns an empty RS rs = md.getUDTs("a", "b", "d", null); boolrc = md.supportsAlterTableWithAddColumn(); LOG.debug("Supports alter table with add column? " + boolrc); boolrc = md.supportsAlterTableWithDropColumn(); LOG.debug("Supports alter table with drop column? " + boolrc); boolrc = md.supportsBatchUpdates(); LOG.debug("Supports batch updates? " + boolrc); boolrc = md.supportsCatalogsInDataManipulation(); LOG.debug("Supports catalogs in data manipulation? " + boolrc); boolrc = md.supportsCatalogsInIndexDefinitions(); LOG.debug("Supports catalogs in index definition? " + boolrc); boolrc = md.supportsCatalogsInPrivilegeDefinitions(); LOG.debug("Supports catalogs in privilege definition? " + boolrc); boolrc = md.supportsCatalogsInProcedureCalls(); LOG.debug("Supports catalogs in procedure calls? " + boolrc); boolrc = md.supportsCatalogsInTableDefinitions(); LOG.debug("Supports catalogs in table definition? " + boolrc); boolrc = md.supportsColumnAliasing(); LOG.debug("Supports column aliasing? " + boolrc); boolrc = md.supportsFullOuterJoins(); LOG.debug("Supports full outer joins? " + boolrc); boolrc = md.supportsGroupBy(); LOG.debug("Supports group by? " + boolrc); boolrc = md.supportsLimitedOuterJoins(); LOG.debug("Supports limited outer joins? " + boolrc); boolrc = md.supportsMultipleResultSets(); LOG.debug("Supports limited outer joins? " + boolrc); boolrc = md.supportsNonNullableColumns(); LOG.debug("Supports non-nullable columns? " + boolrc); boolrc = md.supportsOuterJoins(); LOG.debug("Supports outer joins? " + boolrc); boolrc = md.supportsPositionedDelete(); LOG.debug("Supports positioned delete? " + boolrc); boolrc = md.supportsPositionedUpdate(); LOG.debug("Supports positioned update? " + boolrc); boolrc = md.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); LOG.debug("Supports result set holdability? " + boolrc); boolrc = md.supportsResultSetType(ResultSet.HOLD_CURSORS_OVER_COMMIT); LOG.debug("Supports result set type? " + boolrc); boolrc = md.supportsSavepoints(); LOG.debug("Supports savepoints? " + boolrc); boolrc = md.supportsSchemasInDataManipulation(); LOG.debug("Supports schemas in data manipulation? " + boolrc); boolrc = md.supportsSchemasInIndexDefinitions(); LOG.debug("Supports schemas in index definitions? " + boolrc); boolrc = md.supportsSchemasInPrivilegeDefinitions(); LOG.debug("Supports schemas in privilege definitions? " + boolrc); boolrc = md.supportsSchemasInProcedureCalls(); LOG.debug("Supports schemas in procedure calls? " + boolrc); boolrc = md.supportsSchemasInTableDefinitions(); LOG.debug("Supports schemas in table definitions? " + boolrc); boolrc = md.supportsSelectForUpdate(); LOG.debug("Supports select for update? " + boolrc); boolrc = md.supportsStoredProcedures(); LOG.debug("Supports stored procedures? " + boolrc); boolrc = md.supportsTransactions(); LOG.debug("Supports transactions? " + boolrc); boolrc = md.supportsUnion(); LOG.debug("Supports union? " + boolrc); boolrc = md.supportsUnionAll(); LOG.debug("Supports union all? " + boolrc); }
From source file:org.apache.ddlutils.TestSummaryCreatorTask.java
/** * Adds the data from the test jdbc propertis file to the document. * /*from w w w. ja v a 2 s . c o m*/ * @param element The element to add the relevant database properties to * @param jdbcPropertiesFile The path of the properties file */ protected void addTargetDatabaseInfo(Element element, String jdbcPropertiesFile) throws IOException, BuildException { if (jdbcPropertiesFile == null) { return; } Properties props = readProperties(jdbcPropertiesFile); Connection conn = null; DatabaseMetaData metaData = null; try { String dataSourceClass = props.getProperty( TestAgainstLiveDatabaseBase.DATASOURCE_PROPERTY_PREFIX + "class", BasicDataSource.class.getName()); DataSource dataSource = (DataSource) Class.forName(dataSourceClass).newInstance(); for (Iterator it = props.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); String propName = (String) entry.getKey(); if (propName.startsWith(TestAgainstLiveDatabaseBase.DATASOURCE_PROPERTY_PREFIX) && !propName.equals(TestAgainstLiveDatabaseBase.DATASOURCE_PROPERTY_PREFIX + "class")) { BeanUtils.setProperty(dataSource, propName.substring(TestAgainstLiveDatabaseBase.DATASOURCE_PROPERTY_PREFIX.length()), entry.getValue()); } } String platformName = props.getProperty(TestAgainstLiveDatabaseBase.DDLUTILS_PLATFORM_PROPERTY); if (platformName == null) { platformName = new PlatformUtils().determineDatabaseType(dataSource); if (platformName == null) { throw new BuildException( "Could not determine platform from datasource, please specify it in the jdbc.properties via the ddlutils.platform property"); } } element.addAttribute("platform", platformName); element.addAttribute("dataSourceClass", dataSourceClass); conn = dataSource.getConnection(); metaData = conn.getMetaData(); try { element.addAttribute("dbProductName", metaData.getDatabaseProductName()); } catch (Throwable ex) { // we ignore it } try { element.addAttribute("dbProductVersion", metaData.getDatabaseProductVersion()); } catch (Throwable ex) { // we ignore it } try { int databaseMajorVersion = metaData.getDatabaseMajorVersion(); int databaseMinorVersion = metaData.getDatabaseMinorVersion(); element.addAttribute("dbVersion", databaseMajorVersion + "." + databaseMinorVersion); } catch (Throwable ex) { // we ignore it } try { element.addAttribute("driverName", metaData.getDriverName()); } catch (Throwable ex) { // we ignore it } try { element.addAttribute("driverVersion", metaData.getDriverVersion()); } catch (Throwable ex) { // we ignore it } try { int jdbcMajorVersion = metaData.getJDBCMajorVersion(); int jdbcMinorVersion = metaData.getJDBCMinorVersion(); element.addAttribute("jdbcVersion", jdbcMajorVersion + "." + jdbcMinorVersion); } catch (Throwable ex) { // we ignore it } } catch (Exception ex) { throw new BuildException(ex); } finally { if (conn != null) { try { conn.close(); } catch (SQLException ex) { // we ignore it } } } }
From source file:org.apache.druid.metadata.storage.postgresql.PostgreSQLConnector.java
protected boolean canUpsert(Handle handle) throws SQLException { if (canUpsert == null) { DatabaseMetaData metaData = handle.getConnection().getMetaData(); canUpsert = metaData.getDatabaseMajorVersion() > 9 || (metaData.getDatabaseMajorVersion() == 9 && metaData.getDatabaseMinorVersion() >= 5); }//from ww w.ja v a 2s . co m return canUpsert; }
From source file:org.apache.hadoop.vertica.VerticaUtil.java
public static int verticaVersion(Configuration conf, boolean output) throws IOException { int ver = -1; try {//w ww . j av a 2 s. c o m VerticaConfiguration vtconfig = new VerticaConfiguration(conf); Connection conn = vtconfig.getConnection(output); DatabaseMetaData dbmd = conn.getMetaData(); ver = dbmd.getDatabaseMajorVersion() * 100; ver += dbmd.getDatabaseMinorVersion(); } catch (ClassNotFoundException e) { throw new IOException("Vertica Driver required to use Vertica Input or Output Formatters"); } catch (SQLException e) { throw new IOException(e); } return ver; }
From source file:org.apache.hive.jdbc.TestJdbcDriver2.java
@Test public void testDatabaseMetaData() throws SQLException { DatabaseMetaData meta = con.getMetaData(); assertEquals("Apache Hive", meta.getDatabaseProductName()); assertEquals(HiveVersionInfo.getVersion(), meta.getDatabaseProductVersion()); assertEquals(System.getProperty("hive.version"), meta.getDatabaseProductVersion()); assertTrue("verifying hive version pattern. got " + meta.getDatabaseProductVersion(), Pattern.matches("\\d+\\.\\d+\\.\\d+.*", meta.getDatabaseProductVersion())); assertEquals(DatabaseMetaData.sqlStateSQL99, meta.getSQLStateType()); assertFalse(meta.supportsCatalogsInTableDefinitions()); assertTrue(meta.supportsSchemasInTableDefinitions()); assertTrue(meta.supportsSchemasInDataManipulation()); assertFalse(meta.supportsMultipleResultSets()); assertFalse(meta.supportsStoredProcedures()); assertTrue(meta.supportsAlterTableWithAddColumn()); //-1 indicates malformed version. assertTrue(meta.getDatabaseMajorVersion() > -1); assertTrue(meta.getDatabaseMinorVersion() > -1); }
From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java
/** * This method is called when the dictionary first sees any connection. * It is used to initialize dictionary metadata if needed. If you * override this method, be sure to call * <code>super.connectedConfiguration</code>. *///ww w . j av a2 s. c o m public void connectedConfiguration(Connection conn) throws SQLException { if (!connected) { DatabaseMetaData metaData = null; try { metaData = conn.getMetaData(); databaseProductName = nullSafe(metaData.getDatabaseProductName()); databaseProductVersion = nullSafe(metaData.getDatabaseProductVersion()); setMajorVersion(metaData.getDatabaseMajorVersion()); setMinorVersion(metaData.getDatabaseMinorVersion()); try { // JDBC3-only method, so it might throw an // AbstractMethodError int JDBCMajorVersion = metaData.getJDBCMajorVersion(); isJDBC3 = JDBCMajorVersion >= 3; isJDBC4 = JDBCMajorVersion >= 4; } catch (Throwable t) { // ignore if not JDBC3 } } catch (Exception e) { if (log.isTraceEnabled()) log.trace(e.toString(), e); } if (log.isTraceEnabled()) { log.trace(DBDictionaryFactory.toString(metaData)); if (isJDBC3) { try { log.trace(_loc.get("connection-defaults", new Object[] { conn.getAutoCommit(), conn.getHoldability(), conn.getTransactionIsolation() })); } catch (Throwable t) { log.trace("Unable to trace connection settings", t); } } } // Configure the naming utility if (supportsDelimitedIdentifiers == null) // not explicitly set configureNamingUtil(metaData); // Auto-detect generated keys retrieval support unless user specified it. if (supportsGetGeneratedKeys == null) { supportsGetGeneratedKeys = (isJDBC3) ? metaData.supportsGetGeneratedKeys() : false; } if (log.isInfoEnabled()) { log.info(_loc.get("dict-info", new Object[] { metaData.getDatabaseProductName(), getMajorVersion(), getMinorVersion(), metaData.getDriverName(), metaData.getDriverVersion() })); } } connected = true; }
From source file:org.apache.openjpa.jdbc.sql.MySQLDictionary.java
@Override public void connectedConfiguration(Connection conn) throws SQLException { super.connectedConfiguration(conn); DatabaseMetaData metaData = conn.getMetaData(); int maj = 0;//from w w w . ja va2 s. c o m int min = 0; if (isJDBC3) { maj = metaData.getDatabaseMajorVersion(); min = metaData.getDatabaseMinorVersion(); } else { try { // The product version looks like 4.1.3-nt or 5.1.30 String productVersion = metaData.getDatabaseProductVersion(); int[] versions = getMajorMinorVersions(productVersion); maj = versions[0]; min = versions[1]; } catch (IllegalArgumentException e) { // we don't understand the version format. // That is ok. We just take the default values. if (log.isWarnEnabled()) log.warn(e.toString(), e); } } if (maj < 4 || (maj == 4 && min < 1)) { supportsSubselect = false; allowsAliasInBulkClause = false; supportsForeignKeysComposite = false; } if (maj > 5 || (maj == 5 && min >= 1)) supportsXMLColumn = true; if (metaData.getDriverMajorVersion() < 5) driverDeserializesBlobs = true; }
From source file:org.apache.openjpa.jdbc.sql.PostgresDictionary.java
/** * Determine XML column support and backslash handling. *//* ww w. ja v a2s . c o m*/ public void connectedConfiguration(Connection conn) throws SQLException { super.connectedConfiguration(conn); DatabaseMetaData metaData = conn.getMetaData(); int maj = 0; int min = 0; if (isJDBC3) { maj = metaData.getDatabaseMajorVersion(); min = metaData.getDatabaseMinorVersion(); } else { try { // The product version looks like "8.3.5". String productVersion = metaData.getDatabaseProductVersion(); String majMin[] = productVersion.split("\\."); maj = Integer.parseInt(majMin[0]); min = Integer.parseInt(majMin[1]); } catch (Exception e) { // We don't understand the version format. if (log.isWarnEnabled()) log.warn(e.toString(), e); } } if ((maj >= 9 || (maj == 8 && min >= 3))) { supportsXMLColumn = true; } // Old PostgreSQL requires double-escape for strings. if ((maj <= 8 || (maj == 9 && min == 0))) { requiresSearchStringEscapeForLike = true; searchStringEscape = "\\\\"; } }