List of usage examples for java.sql DatabaseMetaData getDriverName
String getDriverName() throws SQLException;
From source file:TerminalMonitor.java
static public void showVersion(DatabaseMetaData meta) { try {/*from ww w. j a va 2s . c o m*/ System.out.println("TerminalMonitor v2.0"); System.out.println("DBMS: " + meta.getDatabaseProductName() + " " + meta.getDatabaseProductVersion()); System.out.println("JDBC Driver: " + meta.getDriverName() + " " + meta.getDriverVersion()); } catch (SQLException e) { System.out.println("Failed to get version info: " + e.getMessage()); } }
From source file:ca.nrc.cadc.db.DBUtil.java
private static void testDS(DataSource ds, boolean keepOpen) throws SQLException { Connection con = null;//from w w w . j ava 2s.co 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:org.hxzon.util.db.springjdbc.StatementCreatorUtils.java
/** * Set the specified PreparedStatement parameter to null, * respecting database-specific peculiarities. */// w w w.jav a 2s .c om private static void setNull(PreparedStatement ps, int paramIndex, int sqlType, String typeName) throws SQLException { if (sqlType == SqlTypeValue.TYPE_UNKNOWN) { boolean useSetObject = false; Integer sqlTypeToUse = null; DatabaseMetaData dbmd = null; String jdbcDriverName = null; boolean checkGetParameterType = !shouldIgnoreGetParameterType; if (checkGetParameterType && !driversWithNoSupportForGetParameterType.isEmpty()) { try { dbmd = ps.getConnection().getMetaData(); jdbcDriverName = dbmd.getDriverName(); checkGetParameterType = !driversWithNoSupportForGetParameterType.contains(jdbcDriverName); } catch (Throwable ex) { logger.debug("Could not check connection metadata", ex); } } if (checkGetParameterType) { try { sqlTypeToUse = ps.getParameterMetaData().getParameterType(paramIndex); } catch (Throwable ex) { if (logger.isDebugEnabled()) { logger.debug( "JDBC 3.0 getParameterType call not supported - using fallback method instead: " + ex); } } } if (sqlTypeToUse == null) { // JDBC driver not compliant with JDBC 3.0 -> proceed with database-specific checks sqlTypeToUse = Types.NULL; try { if (dbmd == null) { dbmd = ps.getConnection().getMetaData(); } if (jdbcDriverName == null) { jdbcDriverName = dbmd.getDriverName(); } if (checkGetParameterType) { driversWithNoSupportForGetParameterType.add(jdbcDriverName); } String databaseProductName = dbmd.getDatabaseProductName(); if (databaseProductName.startsWith("Informix") || jdbcDriverName.startsWith("Microsoft SQL Server")) { useSetObject = true; } else if (databaseProductName.startsWith("DB2") || jdbcDriverName.startsWith("jConnect") || jdbcDriverName.startsWith("SQLServer") || jdbcDriverName.startsWith("Apache Derby")) { sqlTypeToUse = Types.VARCHAR; } } catch (Throwable ex) { logger.debug("Could not check connection metadata", ex); } } if (useSetObject) { ps.setObject(paramIndex, null); } else { ps.setNull(paramIndex, sqlTypeToUse); } } else if (typeName != null) { ps.setNull(paramIndex, sqlType, typeName); } else { ps.setNull(paramIndex, sqlType); } }
From source file:net.bull.javamelody.internal.model.JavaInformations.java
private static void appendDataBaseVersion(StringBuilder result, Connection connection) throws SQLException { final DatabaseMetaData metaData = connection.getMetaData(); // Scurit: pour l'instant on n'indique pas metaData.getUserName() result.append(metaData.getURL()).append('\n'); result.append(metaData.getDatabaseProductName()).append(", ").append(metaData.getDatabaseProductVersion()) .append('\n'); result.append("Driver JDBC:\n").append(metaData.getDriverName()).append(", ") .append(metaData.getDriverVersion()); }
From source file:com.netspective.axiom.connection.BasicConnectionProviderEntry.java
public void init(String dataSourceId, Connection conn) { this.dataSourceId = dataSourceId; try {/*from w w w . j av a 2 s . co m*/ try { DatabasePolicy policy = DatabasePolicies.getInstance().getDatabasePolicy(conn); put(KEYNAME_DATABASE_POLICY_CLASSNAME, policy.getClass().getName()); put(KEYNAME_DATABASE_POLICY_DBMSID, policy.getDbmsIdentifier()); } catch (Exception dpe) { put(KEYNAME_DATABASE_POLICY_CLASSNAME, dpe.toString()); } DatabaseMetaData dbmd = conn.getMetaData(); put(KEYNAME_DRIVER_NAME, dbmd.getDriverName()); put(KEYNAME_DATABASE_PRODUCT_NAME, dbmd.getDatabaseProductName()); put(KEYNAME_DATABASE_PRODUCT_VERSION, dbmd.getDatabaseProductVersion()); put(KEYNAME_DRIVER_VERSION, dbmd.getDriverVersion()); put(KEYNAME_URL, dbmd.getURL()); put(KEYNAME_USER_NAME, dbmd.getUserName()); String resultSetType = "unknown"; if (dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE)) resultSetType = "scrollable (insensitive)"; else if (dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE)) resultSetType = "scrollable (sensitive)"; else if (dbmd.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY)) resultSetType = "non-scrollabe (forward only)"; put(KEYNAME_RESULTSET_TYPE, resultSetType); valid = true; } catch (Exception e) { exception = e; } finally { try { conn.close(); } catch (SQLException e) { log.error("SQL Exception while closing connection", e); } } }
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 av a 2 s .co m*/ }
From source file:org.tec.webapp.jdbc.service.impl.SystemSvcImpl.java
/** * {@inheritDoc}/*from w w w . j a v a 2s.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.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.focusns.service.env.impl.EnvironmentServiceImpl.java
protected Environment lookupDB() { try {//from w ww .java 2s . co 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:net.certifi.audittablegen.AuditTableGen.java
/** * Examines the DataSource metadata for information pertaining to the * driver, catalog, schema and the presence of audit table configuration * data.// w ww . j av a2 s. com * * @return String containing datasource information. * @throws SQLException */ String getDataSourceInfo() throws SQLException { Connection conn = dataSource.getConnection(); DatabaseMetaData dmd = conn.getMetaData(); StringBuilder s = new StringBuilder(); s.append("Driver Name: ").append(dmd.getDriverName()).append("Driver Version: ") .append(dmd.getDriverVersion()).append(System.lineSeparator()).append("CatalogSeperator: ") .append(dmd.getCatalogSeparator()).append(System.lineSeparator()).append("CatalogTerm: ") .append(dmd.getCatalogTerm()).append(System.lineSeparator()).append("SchemaTerm: ") .append(dmd.getSchemaTerm()).append(System.lineSeparator()).append("Catalogs: "); ResultSet rs = dmd.getCatalogs(); while (rs.next()) { s.append(rs.getString("TABLE_CAT")).append(","); logger.debug("Catalog: {}", rs.getString("TABLE_CAT")); } rs.close(); s.append(System.lineSeparator()); s.append("Schemas: "); rs = dmd.getSchemas(); while (rs.next()) { logger.debug("Schema: {}", rs.getString("TABLE_SCHEM")); s.append("{catalog}:").append(rs.getString("TABLE_CATALOG")).append(" {schema}:") .append(rs.getString("TABLE_SCHEM")).append(","); } rs.close(); s.append(System.lineSeparator()).append("Target Catalog: ").append(catalog).append(System.lineSeparator()) .append("Target Schema: ").append(schema).append(System.lineSeparator()); // if (dmr.hasAuditConfigTable()){ // s.append("Has auditConfigSource table").append(System.lineSeparator()); // } conn.close(); return s.toString(); }