List of usage examples for java.sql DatabaseMetaData getDatabaseProductVersion
String getDatabaseProductVersion() throws SQLException;
From source file:web.mvc.servlets.MyServlet.java
private void fillDataFromDataSource(List<InfoItem> data, DriverManagerDataSource dataSource) throws SQLException { try (Connection connect = dataSource.getConnection()) { DatabaseMetaData metaData = connect.getMetaData(); data.add(new InfoItem("database name", metaData.getDatabaseProductName())); data.add(new InfoItem("database version", metaData.getDatabaseProductVersion())); data.add(new InfoItem("driver name", metaData.getDriverName())); data.add(new InfoItem("driver version", metaData.getDriverVersion())); }/*from ww w. j ava2s.c o m*/ }
From source file:org.alfresco.repo.domain.schema.DataSourceCheck.java
public void init() { logger.info(I18NUtil.getMessage(MSG_DB_CONNECTION, dbUrl, dbUsername)); Connection con = null;/*from w ww.ja v a 2s . c o m*/ try { con = dataSource.getConnection(); con.setAutoCommit(true); DatabaseMetaData meta = con.getMetaData(); logger.info(I18NUtil.getMessage(MSG_DB_VERSION, meta.getDatabaseProductName(), meta.getDatabaseProductVersion())); Dialect dialect = DialectFactory.buildDialect(cfg.getProperties(), meta.getDatabaseProductName(), meta.getDatabaseMajorVersion()); // Check MS SQL Server specific settings if (dialect instanceof SQLServerDialect) { if (transactionIsolation != SQL_SERVER_TRANSACTION_ISOLATION) { throw new AlfrescoRuntimeException(ERR_WRONG_TRANSACTION_ISOLATION_SQL_SERVER, new Object[] { transactionIsolation, SQL_SERVER_TRANSACTION_ISOLATION }); } } } catch (RuntimeException re) { // just rethrow throw re; } catch (Exception e) { throw new AlfrescoRuntimeException(ERR_DB_CONNECTION, new Object[] { e.getMessage() }, e); } finally { try { con.close(); } catch (Exception e) { } } }
From source file:org.sonar.server.platform.monitoring.DatabaseMonitor.java
private void completeDbAttributes(Map<String, Object> attributes) { try (DbSession dbSession = dbClient.openSession(false); Connection connection = dbSession.getConnection()) { DatabaseMetaData metadata = connection.getMetaData(); attributes.put("Database", metadata.getDatabaseProductName()); attributes.put("Database Version", metadata.getDatabaseProductVersion()); attributes.put("Username", metadata.getUserName()); attributes.put("URL", metadata.getURL()); attributes.put("Driver", metadata.getDriverName()); attributes.put("Driver Version", metadata.getDriverVersion()); attributes.put("Version Status", getMigrationStatus()); } catch (SQLException e) { throw new IllegalStateException("Fail to get DB metadata", e); }/*w ww.j a v a2s. c o m*/ }
From source file:org.tec.webapp.jdbc.service.impl.SystemSvcImpl.java
/** * {@inheritDoc}/*from w w w .ja v a2 s. c o m*/ */ @Override() public SerializableList<StatusBean> getStatus() { Connection conn = null; try { SerializableList<StatusBean> slist = new SerializableList<StatusBean>(); // get java information slist.add(new StatusBean("java.version", System.getProperty("java.version"))); //get Servlet information slist.add(new StatusBean("server.info", mServletContext.getServerInfo())); StringBuilder buff = new StringBuilder(); buff.append(mServletContext.getMajorVersion()); buff.append('.'); buff.append(mServletContext.getMinorVersion()); slist.add(new StatusBean("servlet.version", buff.toString())); // get database information conn = mDataSource.getConnection(); DatabaseMetaData dmd = conn.getMetaData(); slist.add(new StatusBean("database.server", dmd.getDatabaseProductName())); slist.add(new StatusBean("database.version", dmd.getDatabaseProductVersion())); slist.add(new StatusBean("jdbc.driver", dmd.getDriverName())); slist.add(new StatusBean("jdbc.driver.version", dmd.getDriverVersion())); // spring slist.add(new StatusBean("spring.version", SpringVersion.getVersion())); return slist; } catch (Throwable e) { throw new RuntimeException("failed to get system status", e); } finally { if (conn != null) { try { conn.close(); } catch (Throwable e) { mLogger.error("failed to get system status", e); } } } }
From source file:org.phenotips.pingback.internal.client.data.DatabasePingDataProviderTest.java
@Test public void provideData() throws Exception { Execution execution = this.mocker.getInstance(Execution.class); ExecutionContext executionContext = mock(ExecutionContext.class); when(execution.getContext()).thenReturn(executionContext); XWikiContext xwikiContext = mock(XWikiContext.class); when(executionContext.getProperty(XWikiContext.EXECUTIONCONTEXT_KEY)).thenReturn(xwikiContext); com.xpn.xwiki.XWiki xwiki = mock(com.xpn.xwiki.XWiki.class); when(xwikiContext.getWiki()).thenReturn(xwiki); XWikiCacheStoreInterface cacheStore = mock(XWikiCacheStoreInterface.class); when(xwiki.getStore()).thenReturn(cacheStore); XWikiHibernateStore store = mock(XWikiHibernateStore.class); when(cacheStore.getStore()).thenReturn(store); DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class); when(store.getDatabaseMetaData()).thenReturn(databaseMetaData); when(databaseMetaData.getDatabaseProductName()).thenReturn("HSQL Database Engine"); when(databaseMetaData.getDatabaseProductVersion()).thenReturn("2.2.9"); JSONAssert.assertEquals("{\"dbName\":\"HSQL Database Engine\",\"dbVersion\":\"2.2.9\"}", new JSONObject(this.mocker.getComponentUnderTest().provideData()), false); }
From source file:org.tec.webapp.orm.service.impl.SystemSvcImpl.java
/** * {@inheritDoc}/*from w w w.ja v a 2 s . co m*/ */ @Override() public SerializableList<StatusBean> getStatus() { Connection conn = null; try { SerializableList<StatusBean> slist = new SerializableList<StatusBean>(); // get java information slist.add(new StatusBean("java.version", System.getProperty("java.version"))); //get Servlet information slist.add(new StatusBean("server.info", mServletContext.getServerInfo())); StringBuilder buff = new StringBuilder(); buff.append(mServletContext.getMajorVersion()); buff.append('.'); buff.append(mServletContext.getMinorVersion()); slist.add(new StatusBean("servlet.version", buff.toString())); // get database information conn = mDataSource.getConnection(); DatabaseMetaData dmd = conn.getMetaData(); slist.add(new StatusBean("database.server", dmd.getDatabaseProductName())); slist.add(new StatusBean("database.version", dmd.getDatabaseProductVersion())); slist.add(new StatusBean("jdbc.driver", dmd.getDriverName())); slist.add(new StatusBean("jdbc.driver.version", dmd.getDriverVersion())); // spring slist.add(new StatusBean("spring.version", SpringVersion.getVersion())); // hibernate slist.add(new StatusBean("hibernate.version", Version.getVersionString())); slist.add(new StatusBean("hibernate.session.factory", mSessionFactory.getClass().getName())); return slist; } catch (Throwable e) { throw new RuntimeException("failed to get system status", e); } finally { if (conn != null) { try { conn.close(); } catch (Throwable e) { mLogger.error("failed to get system status", e); } } } }
From source file:org.rhq.enterprise.server.util.SystemDatabaseInformation.java
private SystemDatabaseInformation() { DataSource ds = null;/*from w ww .j av a2s .co m*/ Connection conn = null; try { ds = LookupUtil.getDataSource(); conn = ds.getConnection(); DatabaseMetaData metadata = conn.getMetaData(); String url = metadata.getURL(); String productName = metadata.getDatabaseProductName(); String productVersion = metadata.getDatabaseProductVersion(); String driverName = metadata.getDriverName(); String driverVersion = metadata.getDriverVersion(); Map<Property, String> values = new HashMap<Property, String>(); values.put(Property.DATABASE_CONNECTION_URL, url); values.put(Property.DATABASE_PRODUCT_NAME, productName); values.put(Property.DATABASE_PRODUCT_VERSION, productVersion); values.put(Property.DATABASE_DRIVER_NAME, driverName); values.put(Property.DATABASE_DRIVER_VERSION, driverVersion); values.put(Property.CURRENT_MEASUREMENT_TABLE, MeasurementDataManagerUtility.getCurrentRawTable()); values.put(Property.NEXT_MEASUREMENT_TABLE_ROTATION, MeasurementDataManagerUtility.getNextRotationTime()); properties = Collections.unmodifiableMap(values); } catch (Exception e) { log.error("Could not load properties for " + SystemDatabaseInformation.class.getSimpleName()); } finally { if (properties == null) { Map<Property, String> values = new HashMap<Property, String>(); for (Property prop : Property.values()) { values.put(prop, "unknown"); } properties = Collections.unmodifiableMap(values); } JDBCUtil.safeClose(conn); } }
From source file:org.openmrs.module.emrmonitor.api.db.hibernate.HibernateEmrMonitorDAO.java
@Override public Map<String, String> getDatabaseMetadata() { final Map<String, String> ret = new LinkedHashMap<String, String>(); sessionFactory.getCurrentSession().doWork(new Work() { @Override// w w w . j av a2s .c o m public void execute(Connection connection) throws SQLException { DatabaseMetaData md = connection.getMetaData(); ret.put("product.name", md.getDatabaseProductName()); ret.put("product.version", md.getDatabaseProductVersion()); ret.put("product.majorVersion", Integer.toString(md.getDatabaseMajorVersion())); ret.put("product.minorVersion", Integer.toString(md.getDatabaseMinorVersion())); } }); return ret; }
From source file:org.focusns.service.env.impl.EnvironmentServiceImpl.java
protected Environment lookupDB() { try {//ww w . j av a2 s . c o m DatabaseMetaData metaData = dataSource.getConnection().getMetaData(); // EnvironmentDB envDB = new EnvironmentDB(); envDB.setDatabaseName(metaData.getDatabaseProductName()); envDB.setDatabaseVersion(metaData.getDatabaseProductVersion()); envDB.setDriverName(metaData.getDriverName()); envDB.setDriverVersion(metaData.getDriverVersion()); envDB.setUrl(metaData.getURL()); envDB.setUsername(metaData.getUserName()); envDB.setMaxConnections(metaData.getMaxConnections()); // metaData.getConnection().close(); // return envDB; } catch (SQLException e) { throw new UnsupportedOperationException(e); } }
From source file:com.predic8.membrane.core.interceptor.statistics.StatisticsJDBCInterceptor.java
private void logDatabaseMetaData(DatabaseMetaData metaData) throws Exception { log.debug("Database metadata:"); log.debug("Name: " + metaData.getDatabaseProductName()); log.debug("Version: " + metaData.getDatabaseProductVersion()); log.debug("idGenerated: " + idGenerated); log.debug("statString: " + statString); }