List of usage examples for java.sql DatabaseMetaData getDriverVersion
String getDriverVersion() throws SQLException;
String
. From source file:com.micromux.cassandra.jdbc.JdbcRegressionTest.java
/** * Create a column group and confirm that the {@code ResultSetMetaData} works. *///from w w w. j ava2 s .c om @Test public void testResultSetMetaData() throws Exception { Statement stmt = con.createStatement(); // Create the target Column family String createCF = "CREATE COLUMNFAMILY t33 (k int PRIMARY KEY," + "c text " + ") ;"; stmt.execute(createCF); stmt.close(); con.close(); // open it up again to see the new CF con = DriverManager .getConnection(String.format("jdbc:cassandra://%s:%d/%s?%s", HOST, PORT, KEYSPACE, OPTIONS)); // paraphrase of the snippet from the ISSUE #33 provided test PreparedStatement statement = con.prepareStatement("update t33 set c=? where k=123"); statement.setString(1, "mark"); statement.executeUpdate(); ResultSet result = statement.executeQuery("SELECT k, c FROM t33;"); ResultSetMetaData metadata = result.getMetaData(); int colCount = metadata.getColumnCount(); System.out.println("Test Issue #33"); DatabaseMetaData md = con.getMetaData(); System.out.println(); System.out.println("--------------"); System.out.println("Driver Version : " + md.getDriverVersion()); System.out.println("DB Version : " + md.getDatabaseProductVersion()); System.out.println("Catalog term : " + md.getCatalogTerm()); System.out.println("Catalog : " + con.getCatalog()); System.out.println("Schema term : " + md.getSchemaTerm()); System.out.println("--------------"); while (result.next()) { metadata = result.getMetaData(); colCount = metadata.getColumnCount(); assertEquals("Total column count should match schema for t33", 2, metadata.getColumnCount()); System.out.printf("(%d) ", result.getRow()); for (int i = 1; i <= colCount; i++) { System.out.print(showColumn(i, result) + " "); switch (i) { case 1: assertEquals("First Column: k", "k", metadata.getColumnName(1)); assertEquals("First Column Type: int", Types.INTEGER, metadata.getColumnType(1)); break; case 2: assertEquals("Second Column: c", "c", metadata.getColumnName(2)); assertEquals("Second Column Type: text", Types.NVARCHAR, metadata.getColumnType(2)); break; } } System.out.println(); } }
From source file:it.greenvulcano.gvesb.j2ee.db.connections.impl.DriverPoolConnectionBuilder.java
public Connection getConnection() throws GVDBException { try {//from www . j a v a2 s . c o 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:com.googlecode.psiprobe.controllers.sql.ConnectionTestController.java
protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { String resourceName = ServletRequestUtils.getStringParameter(request, "resource"); DataSource dataSource = null; try {//from ww w . j a va 2 s . c om dataSource = getContainerWrapper().getResourceResolver().lookupDataSource(context, resourceName, getContainerWrapper()); } catch (NamingException e) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[] { resourceName })); } if (dataSource == null) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[] { resourceName })); } else { try { // TODO: use Spring's jdbc template? Connection conn = dataSource.getConnection(); try { DatabaseMetaData md = conn.getMetaData(); List dbMetaData = new ArrayList(); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.dbProdName", md.getDatabaseProductName()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.dbProdVersion", md.getDatabaseProductVersion()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcDriverName", md.getDriverName()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcDriverVersion", md.getDriverVersion()); // addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcVersion", String.valueOf(md.getJDBCMajorVersion())); return new ModelAndView(getViewName(), "dbMetaData", dbMetaData); } finally { conn.close(); } } catch (SQLException e) { String message = getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.connection.failure", new Object[] { e.getMessage() }); logger.error(message, e); request.setAttribute("errorMessage", message); } } return new ModelAndView(getViewName()); }
From source file:net.testdriven.psiprobe.controllers.sql.ConnectionTestController.java
protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { String resourceName = ServletRequestUtils.getStringParameter(request, "resource"); DataSource dataSource = null; try {//w ww .j av a 2 s .co m dataSource = getContainerWrapper().getResourceResolver().lookupDataSource(context, resourceName); } catch (NamingException e) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[] { resourceName })); } if (dataSource == null) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[] { resourceName })); } else { try { // TODO: use Spring's jdbc template? try (Connection conn = dataSource.getConnection()) { DatabaseMetaData md = conn.getMetaData(); List<Map<String, String>> dbMetaData = new ArrayList<>(); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.dbProdName", md.getDatabaseProductName()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.dbProdVersion", md.getDatabaseProductVersion()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcDriverName", md.getDriverName()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcDriverVersion", md.getDriverVersion()); // addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcVersion", String.valueOf(md.getJDBCMajorVersion())); return new ModelAndView(getViewName(), "dbMetaData", dbMetaData); } } catch (SQLException e) { String message = getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.connection.failure", new Object[] { e.getMessage() }); logger.error(message, e); request.setAttribute("errorMessage", message); } } return new ModelAndView(getViewName()); }
From source file:psiprobe.controllers.sql.ConnectionTestController.java
@Override protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { String resourceName = ServletRequestUtils.getStringParameter(request, "resource"); DataSource dataSource = null; try {/*from w w w . j av a2 s.co m*/ dataSource = getContainerWrapper().getResourceResolver().lookupDataSource(context, resourceName, getContainerWrapper()); } catch (NamingException e) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[] { resourceName })); logger.trace("", e); } if (dataSource == null) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[] { resourceName })); } else { try { // TODO: use Spring's jdbc template? try (Connection conn = dataSource.getConnection()) { DatabaseMetaData md = conn.getMetaData(); List<Map<String, String>> dbMetaData = new ArrayList<>(); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.dbProdName", md.getDatabaseProductName()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.dbProdVersion", md.getDatabaseProductVersion()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcDriverName", md.getDriverName()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcDriverVersion", md.getDriverVersion()); // addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcVersion", // String.valueOf(md.getJDBCMajorVersion())); return new ModelAndView(getViewName(), "dbMetaData", dbMetaData); } } catch (SQLException e) { String message = getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.connection.failure", new Object[] { e.getMessage() }); logger.error(message, e); request.setAttribute("errorMessage", message); } } return new ModelAndView(getViewName()); }
From source file:com.flexive.ejb.beans.configuration.GlobalConfigurationEngineBean.java
/** * {@inheritDoc}//w w w .j a v a 2 s .c o m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public DivisionData createDivisionData(int divisionId, String dataSource, String domainRegEx) { String dbVendor = "unknown"; String dbVersion = "unknown"; String dbDriverVersion = "unknown"; boolean available = false; Connection con = null; try { // lookup non-transactional datasource to avoid issues with the default JEE6 data source in Glassfish con = Database.getDataSource(dataSource + "NoTX").getConnection(); DatabaseMetaData dbmd = con.getMetaData(); dbVendor = dbmd.getDatabaseProductName(); dbVersion = dbmd.getDatabaseProductVersion(); dbDriverVersion = dbmd.getDriverName() + " " + dbmd.getDriverVersion(); available = true; } catch (NamingException e) { LOG.error("Failed to get datasource " + dataSource + " (flagged inactive)"); } catch (SQLException e) { if (LOG.isDebugEnabled()) { LOG.debug("Failed to get database meta information: " + e.getMessage(), e); } } finally { Database.closeObjects(GlobalConfigurationEngineBean.class, con, null); } return new DivisionData(divisionId, available, dataSource, domainRegEx, dbVendor, dbVersion, dbDriverVersion); }
From source file:net.risesoft.soa.asf.web.controller.SystemController.java
private List<SysInfo> getDBInfo() { List list = new ArrayList(); String group = "4. ??"; try {// ww w. ja v a2 s . c om 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.atlassian.jira.startup.JiraSystemInfo.java
/** * Obtains database configuration information. This should be called after the database has been checked for sanity * and hence we can safely do some entityengine.xml and database connection test. But this is before the database is * auto-created and hence the support team can get valuable configuration information before a real DB cockup is * encountered.//from w ww . j ava 2 s . co m */ public void obtainDatabaseConfigurationInfo() { logMsg.outputHeader("Database Configuration"); final URL entityEngineURL = ClassLoaderUtils.getResource("entityengine.xml", getClass()); logMsg.outputProperty("Loading entityengine.xml from", entityEngineURL.toString()); final DatasourceInfo datasourceInfo = connectionFactory.getDatasourceInfo(); if (datasourceInfo != null) { logMsg.outputProperty("Entity model field type name", datasourceInfo.getFieldTypeName()); logMsg.outputProperty("Entity model schema name", datasourceInfo.getSchemaName()); } Connection connection = null; try { connection = connectionFactory.getConnection(); final DatabaseMetaData metaData = connection.getMetaData(); final SystemInfoUtils jiraSysInfo = new SystemInfoUtilsImpl(); logMsg.outputProperty("Database Version", metaData.getDatabaseProductName() + " - " + metaData.getDatabaseProductVersion()); logMsg.outputProperty("Database Driver", metaData.getDriverName() + " - " + metaData.getDriverVersion()); logMsg.outputProperty("Database URL", maskURL(metaData.getURL())); logMsg.outputProperty(jiraSysInfo.getDbDescriptorLabel(), jiraSysInfo.getDbDescriptorValue()); } catch (final SQLException e) { // dont worry about this exception here. Code later one will barf on the same problem and do more appropriate actions. // We are just trying to get startup information for support purposes for now. log.debug(e); } finally { silentlyClose(connection); } }
From source file:com.manydesigns.portofino.model.database.ConnectionProvider.java
public void init(DatabasePlatformsRegistry databasePlatformsRegistry) { Connection conn = null;//from w w w . ja va 2 s . com 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 a v a2 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(); }