List of usage examples for java.sql DatabaseMetaData getDatabaseProductName
String getDatabaseProductName() throws SQLException;
From source file:org.talend.metadata.managment.utils.MetadataConnectionUtils.java
public static boolean isOracle(DatabaseMetaData metadata) { if (metadata != null) { try {//from w ww . ja v a 2 s . c o m String name = metadata.getDatabaseProductName(); if (name != null && name.toUpperCase().equals(EDatabaseTypeName.ORACLEFORSID.getProduct().toUpperCase())) { return true; } } catch (SQLException e) { ExceptionHandler.process(e); } } return false; }
From source file:org.talend.metadata.managment.utils.MetadataConnectionUtils.java
public static boolean isAccess(DatabaseMetaData connectionMetadata) throws SQLException { if (connectionMetadata.getDriverName() != null && connectionMetadata.getDatabaseProductName() != null && connectionMetadata.getDatabaseProductName().equals(DatabaseConstant.MS_ACCESS_PRODUCT_NAME)) { return true; }/*from w w w . jav a2 s . com*/ return false; }
From source file:org.talend.metadata.managment.utils.MetadataConnectionUtils.java
public static boolean isMysql(DatabaseMetaData connectionMetadata) throws SQLException { if (connectionMetadata.getDriverName() != null && connectionMetadata.getDatabaseProductName() != null) { if (EDataBaseType.MySQL.getProductName().equals(connectionMetadata.getDatabaseProductName().trim())) { return true; }/* w w w .ja v a 2s. c o m*/ } return false; }
From source file:org.talend.metadata.managment.utils.MetadataConnectionUtils.java
public static boolean isMssql(DatabaseMetaData connectionMetadata) throws SQLException { if (connectionMetadata.getDriverName() != null && connectionMetadata.getDatabaseProductName() != null) { if (EDataBaseType.Microsoft_SQL_Server.getProductName() .equals(connectionMetadata.getDatabaseProductName().trim())) { return true; }/* w w w . j a v a 2 s .c o m*/ } return false; }
From source file:org.dspace.storage.rdbms.DatabaseUtils.java
/** * Determine the type of Database, based on the DB connection. * /*from w w w. j a v a 2 s. com*/ * @param connection current DB Connection * @return a DB keyword/type (see DatabaseUtils.DBMS_* constants) * @throws SQLException if database error */ public static String getDbType(Connection connection) throws SQLException { DatabaseMetaData meta = connection.getMetaData(); String prodName = meta.getDatabaseProductName(); String dbms_lc = prodName.toLowerCase(Locale.ROOT); if (dbms_lc.contains("postgresql")) { return DBMS_POSTGRES; } else if (dbms_lc.contains("oracle")) { return DBMS_ORACLE; } else if (dbms_lc.contains("h2")) // Used for unit testing only { return DBMS_H2; } else { return dbms_lc; } }
From source file:name.marcelomorales.siqisiqi.bonecp.DataSourceProviderTest.java
@Test public void testOneDatabase() throws Exception { Config config = ConfigFactory.load(); DataSourceProvider dsp = new DataSourceProvider(config); dsp.getBoneCPConfig().setAcquireRetryDelayInMs(2000); DataSource dataSource = dsp.get(); Connection connection = dataSource.getConnection(); DatabaseMetaData metaData = connection.getMetaData(); assertEquals("Apache Derby", metaData.getDatabaseProductName()); connection.close();/*from www . j a va2 s . c om*/ dsp.close(); }
From source file:name.marcelomorales.siqisiqi.bonecp.DataSourceProviderTest.java
@Test public void testWithDependencyInjector() throws Exception { Injector injector = Guice.createInjector(new AbstractModule() { @Override/*from w w w . j a v a 2 s.c o m*/ protected void configure() { bind(Config.class).toInstance(ConfigFactory.load()); bind(DataSourceProvider.class).in(Scopes.SINGLETON); bind(DataSource.class).toProvider(DataSourceProvider.class).in(Scopes.SINGLETON); } }); DataSource dataSource = injector.getInstance(DataSource.class); Connection connection = dataSource.getConnection(); DatabaseMetaData metaData = connection.getMetaData(); assertEquals("Apache Derby", metaData.getDatabaseProductName()); connection.close(); injector.getInstance(DataSourceProvider.class).close(); }
From source file:org.talend.metadata.managment.utils.MetadataConnectionUtils.java
public static boolean isPostgresql(DatabaseMetaData connectionMetadata) throws SQLException { if (connectionMetadata != null) { String databaseProductName = connectionMetadata.getDatabaseProductName(); if (databaseProductName != null) { return databaseProductName.toLowerCase().indexOf(DatabaseConstant.POSTGRESQL_PRODUCT_NAME) > -1; }//from w ww.j a v a 2 s. c om } return false; }
From source file:org.beangle.webapp.database.action.DatasourceAction.java
public String test() { Long datasourceId = getEntityId("datasource"); DataSource dataSource = datasourceService.getDatasource(datasourceId); Map<String, String> driverinfo = CollectUtils.newHashMap(); Map<String, Object> dbinfo = CollectUtils.newHashMap(); Map<String, Object> jdbcinfo = CollectUtils.newHashMap(); Connection con = null;//from w ww . j ava2s. co m try { con = dataSource.getConnection(); if (con != null) { java.sql.DatabaseMetaData dm = con.getMetaData(); driverinfo.put("Driver Name", dm.getDriverName()); driverinfo.put("Driver Version", dm.getDriverVersion()); dbinfo.put("Database Name", dm.getDatabaseProductName()); dbinfo.put("Database Version", dm.getDatabaseProductVersion()); jdbcinfo.put("JDBC Version", dm.getJDBCMajorVersion() + "." + dm.getJDBCMinorVersion()); StringBuilder catelogs = new StringBuilder(); dbinfo.put("Avalilable Catalogs", catelogs); java.sql.ResultSet rs = dm.getCatalogs(); while (rs.next()) { catelogs.append(rs.getString(1)); if (rs.next()) catelogs.append(','); } rs.close(); } } catch (Exception e) { put("exceptionStack", ExceptionUtils.getFullStackTrace(e)); } finally { try { if (con != null) con.close(); con = null; } catch (Exception e) { e.printStackTrace(); } } put("driverinfo", driverinfo); put("dbinfo", dbinfo); put("jdbcinfo", jdbcinfo); return forward(); }
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); }