Java Code Examples for java.sql.DatabaseMetaData#getDatabaseProductVersion()
The following examples show how to use
java.sql.DatabaseMetaData#getDatabaseProductVersion() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatabaseStatusChecker.java From dubbox with Apache License 2.0 | 5 votes |
public Status check() { boolean ok; try { Connection connection = dataSource.getConnection(); try { DatabaseMetaData metaData = connection.getMetaData(); ResultSet resultSet = metaData.getTypeInfo(); try { ok = resultSet.next(); } finally { resultSet.close(); } if (message == null) { message = metaData.getURL() + " (" + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion() + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")"; } if (version == 0) { version = metaData.getDatabaseMajorVersion(); } } finally { connection.close(); } } catch (Throwable e) { logger.error(e.getMessage(), e); ok = false; } return new Status(! ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message); }
Example 2
Source File: RepositoryConnectionEditor.java From MogwaiERDesignerNG with GNU General Public License v3.0 | 5 votes |
private void commandTest() { if (bindingInfo.validate().isEmpty()) { bindingInfo.view2model(); DatabaseConnectionDatamodel theModel = bindingInfo .getDefaultModel(); Dialect theDialect = theModel.getDialect(); try { Connection theConnection = theDialect.createConnection( ApplicationPreferences.getInstance() .createDriverClassLoader(), theModel .getDriver(), theModel.getUrl(), theModel .getUser(), theModel.getPassword(), false); DatabaseMetaData theMeta = theConnection.getMetaData(); String theDB = theMeta.getDatabaseProductName(); String theVersion = theMeta.getDatabaseProductVersion(); if (!theDialect.generatesManagedConnection()) { theConnection.close(); } MessagesHelper.displayInfoMessage(this, getResourceHelper() .getText(ERDesignerBundle.CONNECTIONSEEMSTOBEOK) + " DB : " + theDB + " " + theVersion); } catch (Exception e) { MessagesHelper.displayErrorMessage(this, e.getMessage()); } } }
Example 3
Source File: StartedListener.java From halo with GNU General Public License v3.0 | 5 votes |
/** * Migrate database. */ private void migrate() throws SQLException { log.info("Starting migrate database..."); Flyway flyway = Flyway .configure() .locations("classpath:/migration") .baselineVersion("1") .baselineOnMigrate(true) .dataSource(url, username, password) .load(); flyway.repair(); flyway.migrate(); // Gets database connection Connection connection = flyway.getConfiguration().getDataSource().getConnection(); // Gets database metadata DatabaseMetaData databaseMetaData = JdbcUtils.getDatabaseMetaData(connection); // Gets database product name HaloConst.DATABASE_PRODUCT_NAME = databaseMetaData.getDatabaseProductName() + " " + databaseMetaData.getDatabaseProductVersion(); // Close connection. connection.close(); log.info("Migrate database succeed."); }
Example 4
Source File: DatabaseStatusChecker.java From dubbox with Apache License 2.0 | 5 votes |
public Status check() { boolean ok; try { Connection connection = dataSource.getConnection(); try { DatabaseMetaData metaData = connection.getMetaData(); ResultSet resultSet = metaData.getTypeInfo(); try { ok = resultSet.next(); } finally { resultSet.close(); } if (message == null) { message = metaData.getURL() + " (" + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion() + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")"; } if (version == 0) { version = metaData.getDatabaseMajorVersion(); } } finally { connection.close(); } } catch (Throwable e) { logger.error(e.getMessage(), e); ok = false; } return new Status(! ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message); }
Example 5
Source File: DatabaseStatusChecker.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public Status check() { boolean ok; try { Connection connection = dataSource.getConnection(); try { DatabaseMetaData metaData = connection.getMetaData(); ResultSet resultSet = metaData.getTypeInfo(); try { ok = resultSet.next(); } finally { resultSet.close(); } if (message == null) { message = metaData.getURL() + " (" + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion() + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")"; } if (version == 0) { version = metaData.getDatabaseMajorVersion(); } } finally { connection.close(); } } catch (Throwable e) { logger.error(e.getMessage(), e); ok = false; } return new Status(! ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message); }
Example 6
Source File: DatabaseStatusChecker.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public Status check() { boolean ok; try { Connection connection = dataSource.getConnection(); try { DatabaseMetaData metaData = connection.getMetaData(); ResultSet resultSet = metaData.getTypeInfo(); try { ok = resultSet.next(); } finally { resultSet.close(); } if (message == null) { message = metaData.getURL() + " (" + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion() + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")"; } if (version == 0) { version = metaData.getDatabaseMajorVersion(); } } finally { connection.close(); } } catch (Throwable e) { logger.error(e.getMessage(), e); ok = false; } return new Status(! ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message); }
Example 7
Source File: AbstractPipelineMavenPluginDao.java From pipeline-maven-plugin with MIT License | 5 votes |
protected String getDatabaseDescription() { try (Connection cnn = ds.getConnection()) { DatabaseMetaData metaData = cnn.getMetaData(); return metaData. getDatabaseProductName() + " " + metaData.getDatabaseProductVersion(); } catch (SQLException e) { return "#" + e.toString() + "#"; } }
Example 8
Source File: DatabaseStatusChecker.java From dubbo3 with Apache License 2.0 | 5 votes |
public Status check() { boolean ok; try { Connection connection = dataSource.getConnection(); try { DatabaseMetaData metaData = connection.getMetaData(); ResultSet resultSet = metaData.getTypeInfo(); try { ok = resultSet.next(); } finally { resultSet.close(); } if (message == null) { message = metaData.getURL() + " (" + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion() + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")"; } if (version == 0) { version = metaData.getDatabaseMajorVersion(); } } finally { connection.close(); } } catch (Throwable e) { logger.error(e.getMessage(), e); ok = false; } return new Status(! ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message); }
Example 9
Source File: DatabaseStatusChecker.java From dubbo3 with Apache License 2.0 | 5 votes |
public Status check() { boolean ok; try { Connection connection = dataSource.getConnection(); try { DatabaseMetaData metaData = connection.getMetaData(); ResultSet resultSet = metaData.getTypeInfo(); try { ok = resultSet.next(); } finally { resultSet.close(); } if (message == null) { message = metaData.getURL() + " (" + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion() + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")"; } if (version == 0) { version = metaData.getDatabaseMajorVersion(); } } finally { connection.close(); } } catch (Throwable e) { logger.error(e.getMessage(), e); ok = false; } return new Status(! ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message); }
Example 10
Source File: DatabaseMetaDataTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Methods that describe the version of the * driver and database. */ public void testVersionInfo() throws SQLException { DatabaseMetaData dmd = getDMD(); int databaseMajor = dmd.getDatabaseMajorVersion(); int databaseMinor = dmd.getDatabaseMinorVersion(); int driverMajor = dmd.getDriverMajorVersion(); int driverMinor = dmd.getDriverMinorVersion(); String databaseVersion = dmd.getDatabaseProductVersion(); String driverVersion = dmd.getDriverVersion(); if (usingEmbedded()) { // Database *is* the driver. assertEquals("Embedded Major version ", databaseMajor, driverMajor); assertEquals("Embedded Minor version ", databaseMinor, driverMinor); assertEquals("Embedded version", databaseVersion, driverVersion); } assertEquals("GemFireXD", dmd.getDatabaseProductName()); String driverName = dmd.getDriverName(); if (usingEmbedded()) { assertEquals("GemFireXD Embedded JDBC Driver", driverName); } else if (usingDerbyNetClient()) { assertEquals("GemFireXD Network Client JDBC Driver", driverName); } int jdbcMajor = dmd.getJDBCMajorVersion(); int jdbcMinor = dmd.getJDBCMinorVersion(); int expectedJDBCMajor = -1; if (JDBC.vmSupportsJDBC4()) { expectedJDBCMajor = 4; } else if (JDBC.vmSupportsJDBC3()) { expectedJDBCMajor = 3; } else if (JDBC.vmSupportsJSR169()) { // Not sure what is the correct output for JSR 169 expectedJDBCMajor = -1; } if (expectedJDBCMajor != -1) { assertEquals("JDBC Major version", expectedJDBCMajor, jdbcMajor); assertEquals("JDBC Minor version", 0, jdbcMinor); } }
Example 11
Source File: SqlDialectFactoryImpl.java From Bats with Apache License 2.0 | 4 votes |
public SqlDialect create(DatabaseMetaData databaseMetaData) { String databaseProductName; int databaseMajorVersion; int databaseMinorVersion; String databaseVersion; try { databaseProductName = databaseMetaData.getDatabaseProductName(); databaseMajorVersion = databaseMetaData.getDatabaseMajorVersion(); databaseMinorVersion = databaseMetaData.getDatabaseMinorVersion(); databaseVersion = databaseMetaData.getDatabaseProductVersion(); } catch (SQLException e) { throw new RuntimeException("while detecting database product", e); } final String upperProductName = databaseProductName.toUpperCase(Locale.ROOT).trim(); final String quoteString = getIdentifierQuoteString(databaseMetaData); final NullCollation nullCollation = getNullCollation(databaseMetaData); final SqlDialect.Context c = SqlDialect.EMPTY_CONTEXT .withDatabaseProductName(databaseProductName) .withDatabaseMajorVersion(databaseMajorVersion) .withDatabaseMinorVersion(databaseMinorVersion) .withDatabaseVersion(databaseVersion) .withIdentifierQuoteString(quoteString) .withNullCollation(nullCollation); switch (upperProductName) { case "ACCESS": return new AccessSqlDialect(c); case "APACHE DERBY": return new DerbySqlDialect(c); case "DBMS:CLOUDSCAPE": return new DerbySqlDialect(c); case "HIVE": return new HiveSqlDialect(c); case "INGRES": return new IngresSqlDialect(c); case "INTERBASE": return new InterbaseSqlDialect(c); case "JETHRODATA": return new JethroDataSqlDialect( c.withJethroInfo(jethroCache.get(databaseMetaData))); case "LUCIDDB": return new LucidDbSqlDialect(c); case "ORACLE": return new OracleSqlDialect(c); case "PHOENIX": return new PhoenixSqlDialect(c); case "MYSQL (INFOBRIGHT)": return new InfobrightSqlDialect(c); case "MYSQL": return new MysqlSqlDialect(c); case "REDSHIFT": return new RedshiftSqlDialect(c); case "SPARK": return new SparkSqlDialect(c); } // Now the fuzzy matches. if (databaseProductName.startsWith("DB2")) { return new Db2SqlDialect(c); } else if (upperProductName.contains("FIREBIRD")) { return new FirebirdSqlDialect(c); } else if (databaseProductName.startsWith("Informix")) { return new InformixSqlDialect(c); } else if (upperProductName.contains("NETEZZA")) { return new NetezzaSqlDialect(c); } else if (upperProductName.contains("PARACCEL")) { return new ParaccelSqlDialect(c); } else if (databaseProductName.startsWith("HP Neoview")) { return new NeoviewSqlDialect(c); } else if (upperProductName.contains("POSTGRE")) { return new PostgresqlSqlDialect(c); } else if (upperProductName.contains("SQL SERVER")) { return new MssqlSqlDialect(c); } else if (upperProductName.contains("SYBASE")) { return new SybaseSqlDialect(c); } else if (upperProductName.contains("TERADATA")) { return new TeradataSqlDialect(c); } else if (upperProductName.contains("HSQL")) { return new HsqldbSqlDialect(c); } else if (upperProductName.contains("H2")) { return new H2SqlDialect(c); } else if (upperProductName.contains("VERTICA")) { return new VerticaSqlDialect(c); } else if (upperProductName.contains("SPARK")) { return new SparkSqlDialect(c); } else { return new AnsiSqlDialect(c); } }
Example 12
Source File: HsqlDatabase.java From barleydb with GNU Lesser General Public License v3.0 | 4 votes |
public HsqlDatabase(DatabaseMetaData metaData) throws SQLException { info = metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion(); }
Example 13
Source File: PostgresqlDatabase.java From barleydb with GNU Lesser General Public License v3.0 | 4 votes |
public PostgresqlDatabase(DatabaseMetaData metaData) throws SQLException { info = metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion(); }
Example 14
Source File: OracleDatabase.java From barleydb with GNU Lesser General Public License v3.0 | 4 votes |
public OracleDatabase(DatabaseMetaData metaData) throws SQLException { info = metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion(); }
Example 15
Source File: SqlServerDatabase.java From barleydb with GNU Lesser General Public License v3.0 | 4 votes |
public SqlServerDatabase(DatabaseMetaData metaData) throws SQLException { info = metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion(); supportsMultipleResultSets = metaData.supportsMultipleResultSets(); supportsSelectForUpdate = metaData.supportsSelectForUpdate(); }
Example 16
Source File: BizDataObjectBehaviorImpl.java From FoxBPM with Apache License 2.0 | 4 votes |
public List<BizDataObject> getDataObjects(String dataSource) { LOG.debug("getDataObjects(String dataSource),dataSource=" + dataSource); try { JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils.getDataSource()); DatabaseMetaData dm = DBUtils.getDataSource().getConnection().getMetaData(); String databaseType = dm.getDatabaseProductName(); String databaseVersion = dm.getDatabaseProductVersion(); LOG.info("the database type is " + databaseType + ",version is " + databaseVersion); // 定义sql返回结果集 SqlRowSet rs = null; boolean isOracle = false; if (MySQL_TYPE.equalsIgnoreCase(databaseType)) { // 获取此 当前数据源连接 对象的当前目录名称。 String catalog = jdbcTemplate.getDataSource().getConnection().getCatalog(); LOG.info("the sql is " + TABLE_INFOR); rs = jdbcTemplate.queryForRowSet(TABLE_INFOR, new Object[]{catalog}); } else if (ORACLE_TYPE.equalsIgnoreCase(databaseType)) { isOracle = true; StringBuffer sql = new StringBuffer("select distinct t_col.DATA_TYPE,t_col.TABLE_NAME,t_col.COLUMN_NAME,t_des.comments as TABLE_COMMENT,c_des.comments as COLUMN_COMMENT from user_tab_columns t_col,user_col_comments c_des,user_tab_comments t_des ").append("where t_col.table_name = c_des.table_name and t_col.table_name = t_des.table_name order by t_col.table_name"); rs = jdbcTemplate.queryForRowSet(sql.toString()); } else if("mssql".equalsIgnoreCase(databaseType)){ } List<BizDataObject> bizDataObjects = new ArrayList<BizDataObject>(); BizDataObject bizDataObject = null; DataVariableDefinition dataVariableDefine = null; String tableName = null; StringBuffer sbExpression = new StringBuffer(); if(rs != null){ // 获取表信息 while (rs.next()) { // 处理首次和区分不同表 if (!rs.getString(TABLE_NAME).equals(tableName)) { bizDataObject = new BizDataObject(); bizDataObject.setId(rs.getString(TABLE_NAME)); if (isOracle) { bizDataObject.setName(rs.getString(TABLE_COMMENT)); } bizDataObject.setDataSource(dataSource); // 添加业务数据对象 bizDataObjects.add(bizDataObject); } dataVariableDefine = new DataVariableDefinition(); dataVariableDefine.setId(rs.getString(COLUMN_NAME)); dataVariableDefine.setFieldName(rs.getString(COLUMN_NAME)); dataVariableDefine.setDataType(rs.getString(DATA_TYPE)); // 生成表达式 sbExpression.append("import org.foxbpm.engine.impl.util.DataVarUtil;\n"); sbExpression.append("DataVarUtil.getInstance().getDataValue("); sbExpression.append("\"" + dataSource + "\"").append(',').append("processInfo.getProcessInstance().getBizKey(),"); sbExpression.append("\"" + dataVariableDefine.getId() + "\""); sbExpression.append(",processInfo);"); dataVariableDefine.setExpression(sbExpression.toString()); dataVariableDefine.setDocumentation(rs.getString(COLUMN_COMMENT)); dataVariableDefine.setBizType(Constant.DB_BIZTYPE); // 添加数据变量定义 bizDataObject.getDataVariableDefinitions().add(dataVariableDefine); tableName = rs.getString(TABLE_NAME); // 清空sbExpression缓存 sbExpression.delete(0, sbExpression.length()); }} LOG.debug("end getDataObjects(String dataSource)"); return bizDataObjects; } catch (SQLException e) { throw ExceptionUtil.getException("获取数据对象失败",e); } }
Example 17
Source File: ConnectionUtil.java From nextreports-server with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public static List<IdName> getValues(StorageService storageService, DataSource dataSource, String select) throws Exception { Connection con = null; List values = new ArrayList(); Dialect dialect; ResultSet rs = null; Statement stmt = null; try { con = ConnectionUtil.createConnection(storageService, dataSource); DatabaseMetaData dbmd = con.getMetaData(); String dbName = dbmd.getDatabaseProductName(); String dbVersion = dbmd.getDatabaseProductVersion(); dialect = DialectFactory.determineDialect(dbName, dbVersion); stmt = con.createStatement(); rs = stmt.executeQuery(select); ResultSetMetaData rsmd = rs.getMetaData(); String type = rsmd.getColumnTypeName(1); int precision = rsmd.getPrecision(1); int scale = rsmd.getScale(1); int typeCode = dialect.getJdbcType(type, precision, scale); while (rs.next()) { Serializable s; switch (typeCode) { case Types.INTEGER: s = rs.getInt(1); break; case Types.DOUBLE: s = rs.getDouble(1); break; case Types.DATE: s = rs.getDate(1); break; case Types.VARCHAR: s = rs.getString(1); break; default: s = rs.getString(1); break; } IdName in = new IdName(); in.setId(s); in.setName(rs.getString(2)); values.add(in); } } finally { ConnectionUtil.closeResultSet(rs); ConnectionUtil.closeStatement(stmt); ConnectionUtil.closeConnection(con); } return values; }
Example 18
Source File: Globals.java From nextreports-designer with Apache License 2.0 | 4 votes |
public static String getDatabaseVersion(Connection conn) throws Exception { DatabaseMetaData dbmd = conn.getMetaData(); return dbmd.getDatabaseProductVersion(); }
Example 19
Source File: DatabaseConnectionEditor.java From MogwaiERDesignerNG with GNU General Public License v3.0 | 4 votes |
private void commandTest() { if (bindingInfo.validate().isEmpty()) { bindingInfo.view2model(); DatabaseConnectionDatamodel theModel = bindingInfo .getDefaultModel(); Dialect theDialect = theModel.getDialect(); try { Connection theConnection = theDialect.createConnection( ApplicationPreferences.getInstance() .createDriverClassLoader(), theModel .getDriver(), theModel.getUrl(), theModel .getUser(), theModel.getPassword(), theModel .isPromptForPassword()); if (theConnection == null) { return; } DatabaseMetaData theMeta = theConnection.getMetaData(); String theDB = theMeta.getDatabaseProductName(); String theVersion = theMeta.getDatabaseProductVersion(); if (!theDialect.generatesManagedConnection()) { theConnection.close(); } MessagesHelper.displayInfoMessage(this, getResourceHelper() .getText(ERDesignerBundle.CONNECTIONSEEMSTOBEOK) + " DB : " + theDB + " " + theVersion); } catch (Exception e) { MessagesHelper.displayErrorMessage(this, e.getMessage()); } } }
Example 20
Source File: ConnectionUtil.java From nextreports-server with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public static List<IdName> getValues(String select, Connection con) throws Exception { List values = new ArrayList(); Dialect dialect; DatabaseMetaData dbmd = con.getMetaData(); String dbName = dbmd.getDatabaseProductName(); String dbVersion = dbmd.getDatabaseProductVersion(); dialect = DialectFactory.determineDialect(dbName, dbVersion); ResultSet rs = null; Statement stmt = null; try { stmt = con.createStatement(); rs = stmt.executeQuery(select); ResultSetMetaData rsmd = rs.getMetaData(); String type = rsmd.getColumnTypeName(1); int precision = rsmd.getPrecision(1); int scale = rsmd.getScale(1); int typeCode = dialect.getJdbcType(type, precision, scale); while (rs.next()) { Serializable s; switch (typeCode) { case Types.INTEGER: s = rs.getInt(1); break; case Types.DOUBLE: s = rs.getDouble(1); break; case Types.DATE: s = rs.getDate(1); break; case Types.VARCHAR: s = rs.getString(1); break; default: s = rs.getString(1); break; } IdName in = new IdName(); in.setId(s); in.setName(rs.getString(2)); values.add(in); } } finally { ConnectionUtil.closeResultSet(rs); ConnectionUtil.closeStatement(stmt); } return values; }