List of usage examples for java.sql DatabaseMetaData getDriverName
String getDriverName() throws SQLException;
From source file:org.talend.metadata.managment.utils.MetadataConnectionUtils.java
public static boolean isOdbcExcel(DatabaseMetaData connectionMetadata) throws SQLException { if (connectionMetadata.getDriverName() != null && connectionMetadata.getDriverName().toLowerCase().startsWith(DatabaseConstant.ODBC_DRIVER_NAME) && connectionMetadata.getDatabaseProductName() != null && connectionMetadata.getDatabaseProductName().equals(DatabaseConstant.ODBC_EXCEL_PRODUCT_NAME)) { return true; }//from ww w. ja v a2 s . c o m 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 ww .ja v a 2s . c o m return false; }
From source file:org.talend.metadata.managment.utils.MetadataConnectionUtils.java
public static boolean isSybase(DatabaseMetaData connectionMetadata) throws SQLException { if (connectionMetadata instanceof SybaseDatabaseMetaData) { return true; }/*w w w . j av a 2 s . c om*/ if (connectionMetadata.getDriverName() != null && connectionMetadata.getDatabaseProductName() != null) { for (String keyString : getSybaseDBProductsName()) { if (keyString.trim().equals(connectionMetadata.getDatabaseProductName().trim())) { return true; } } } return false; }
From source file:org.talend.metadata.managment.utils.MetadataConnectionUtils.java
/** * zshen Comment method "isOdbcConnection". feature 10630 * // ww w. j a v a 2s . c o m * @param connection * @return * @throws SQLException */ public static boolean isOdbcConnection(DatabaseMetaData connectionMetadata) throws SQLException { if (connectionMetadata.getDriverName() != null && connectionMetadata.getDriverName().toLowerCase().startsWith(DatabaseConstant.ODBC_DRIVER_NAME)) { return true; } 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 va 2s . c om*/ } 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; }/*from w ww .j a v a2s.c o m*/ } return false; }
From source file:org.wso2.carbon.server.admin.service.ServerAdmin.java
public ServerData getServerData() throws Exception { boolean isRestricted = true; MessageContext msgContext = MessageContext.getCurrentMessageContext(); if (msgContext != null) { HttpServletRequest request = (HttpServletRequest) msgContext .getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); HttpSession httpSession = request.getSession(false); if (httpSession != null) { String userName = (String) httpSession.getAttribute(ServerConstants.USER_LOGGED_IN); isRestricted = !getUserRealm().getAuthorizationManager().isUserAuthorized(userName, "/permission/protected/server-admin/homepage", CarbonConstants.UI_PERMISSION_ACTION); }/* ww w . j av a 2 s . com*/ } else { // non SOAP call isRestricted = false; } String location = null; if (!isRestricted) { location = getAxisConfig().getRepository().toString(); } ServerData data = new ServerData(ServerConstants.SERVER_NAME, location, (getTenantDomain() != null && !getTenantDomain().equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)), isRestricted); if (!isRestricted) { Parameter systemStartTime = getAxisConfig().getParameter(CarbonConstants.SERVER_START_TIME); long startTime = 0; if (systemStartTime != null) { startTime = Long.parseLong((String) systemStartTime.getValue()); } Date stTime = new Date(startTime); SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss"); data.setServerStartTime(dateFormatter.format(stTime)); data.setServerUpTime(getTime((System.currentTimeMillis() - startTime) / 1000)); Parameter systemStartUpDuration = getAxisConfig().getParameter(CarbonConstants.START_UP_DURATION); if (systemStartUpDuration != null) { data.setServerStartUpDuration((String) systemStartUpDuration.getValue()); } ServerConfigurationService serverConfig = dataHolder.getServerConfig(); String registryType = serverConfig.getFirstProperty("Registry.Type"); if (registryType == null) { registryType = "embedded"; } data.setRegistryType(registryType); // Extract DB related data from RegistryContext if (registryType.equals("embedded")) { try { DataAccessManager dataAccessManager = RegistryContext.getBaseInstance().getDataAccessManager(); if (!(dataAccessManager instanceof JDBCDataAccessManager)) { String msg = "Failed to obtain DB connection. Invalid data access manager."; log.error(msg); throw new AxisFault(msg); } DataSource dataSource = ((JDBCDataAccessManager) dataAccessManager).getDataSource(); Connection dbConnection = dataSource.getConnection(); DatabaseMetaData metaData = dbConnection.getMetaData(); if (metaData != null) { data.setDbName(metaData.getDatabaseProductName()); data.setDbVersion(metaData.getDatabaseProductVersion()); data.setDbDriverName(metaData.getDriverName()); data.setDbDriverVersion(metaData.getDriverVersion()); data.setDbURL(metaData.getURL()); } dbConnection.close(); } catch (SQLException e) { String msg = "Cannot create DB connection"; log.error(msg, e); throw new AxisFault(msg, e); } } else if (registryType.equals("remote")) { data.setRemoteRegistryChroot(serverConfig.getFirstProperty("Registry.Chroot")); data.setRemoteRegistryURL(serverConfig.getFirstProperty("Registry.Url")); } } try { data.setServerIp(NetworkUtils.getLocalHostname()); } catch (SocketException e) { throw new AxisFault(e.getMessage(), e); } return data; }
From source file:ro.nextreports.designer.dbviewer.DefaultDBViewer.java
public DBInfo getDBInfo(String schemaName, int mask, Connection con) throws NextSqlException { String info = ""; List<String> keywords = new ArrayList<String>(); List<DBTable> tables = new ArrayList<DBTable>(); List<DBProcedure> procedures = new ArrayList<DBProcedure>(); Dialect dialect;//w ww .j a v a 2 s. co m try { dialect = DialectUtil.getDialect(con); } catch (Exception ex) { ex.printStackTrace(); throw new NextSqlException("Could not get Dialect.", ex); } try { DatabaseMetaData dbmd = con.getMetaData(); if ((mask & DBInfo.INFO) == DBInfo.INFO) { StringBuffer sb = new StringBuffer(); sb.append(I18NSupport.getString("database.product")).append(dbmd.getDatabaseProductName()) .append("\r\n"); sb.append(I18NSupport.getString("database.product.version")) .append(dbmd.getDatabaseProductVersion()).append("\r\n"); sb.append(I18NSupport.getString("database.driver.name")).append(dbmd.getDriverName()) .append("\r\n"); sb.append(I18NSupport.getString("database.driver.version")).append(dbmd.getDriverVersion()) .append("\r\n"); info = sb.toString(); } if ((mask & DBInfo.SUPPORTED_KEYWORDS) == DBInfo.SUPPORTED_KEYWORDS) { StringTokenizer st = new StringTokenizer(dbmd.getSQLKeywords(), ","); while (st.hasMoreTokens()) { keywords.add(st.nextToken()); } } // Get a ResultSet that contains all of the tables in this database // We specify a table_type of "TABLE" to prevent seeing system tables, // views and so forth boolean tableMask = ((mask & DBInfo.TABLES) == DBInfo.TABLES); boolean viewMask = ((mask & DBInfo.VIEWS) == DBInfo.VIEWS); if (tableMask || viewMask) { String[] tableTypes; if (tableMask && viewMask) { tableTypes = new String[] { "TABLE", "VIEW" }; } else if (tableMask) { tableTypes = new String[] { "TABLE" }; } else { tableTypes = new String[] { "VIEW" }; } String pattern = tableMask ? Globals.getTableNamePattern() : Globals.getViewNamePattern(); ResultSet allTables = dbmd.getTables(null, schemaName, pattern, tableTypes); try { while (allTables.next()) { String table_name = allTables.getString("TABLE_NAME"); String table_type = allTables.getString("TABLE_TYPE"); // discard recycle bin tables String ignoreTablePrefix = dialect.getRecycleBinTablePrefix(); if ((table_name == null) || ((ignoreTablePrefix != null) && table_name.startsWith(ignoreTablePrefix))) { continue; } if ((mask & DBInfo.INDEXES) == DBInfo.INDEXES) { ResultSet indexList = null; try { // Get a list of all the indexes for this table indexList = dbmd.getIndexInfo(null, schemaName, table_name, false, false); List<DBIndex> indexes = new ArrayList<DBIndex>(); while (indexList.next()) { String index_name = indexList.getString("INDEX_NAME"); String column_name = indexList.getString("COLUMN_NAME"); if (!index_name.equals("null")) { DBIndex index = new DBIndex(index_name, column_name); indexes.add(index); } } DBTable table = new DBTable(schemaName, table_name, table_type, indexes); tables.add(table); } catch (SQLException e) { throw new NextSqlException("SQL Exception: " + e.getMessage(), e); } finally { closeResultSet(indexList); } } else { DBTable table = new DBTable(schemaName, table_name, table_type); tables.add(table); } } } catch (SQLException e) { throw new NextSqlException("SQL Exception: " + e.getMessage(), e); } finally { closeResultSet(allTables); } } boolean procedureMask = ((mask & DBInfo.PROCEDURES) == DBInfo.PROCEDURES); if (procedureMask) { String pattern = Globals.getProcedureNamePattern(); if (pattern == null) { pattern = "%"; } ResultSet rs = dbmd.getProcedures(null, schemaName, pattern); try { while (rs.next()) { String spName = rs.getString("PROCEDURE_NAME"); int spType = rs.getInt("PROCEDURE_TYPE"); String catalog = rs.getString("PROCEDURE_CAT"); // System.out.println("Stored Procedure Name: " + spName); // if (spType == DatabaseMetaData.procedureReturnsResult) { // System.out.println("procedure Returns Result"); // } else if (spType == DatabaseMetaData.procedureNoResult) { // System.out.println("procedure No Result"); // } else { // System.out.println("procedure Result unknown"); // } procedures.add(new DBProcedure(schemaName, catalog, spName, spType)); } } catch (SQLException e) { throw new NextSqlException("SQL Exception: " + e.getMessage(), e); } finally { closeResultSet(rs); } } } catch (SQLException e) { LOG.error(e.getMessage(), e); e.printStackTrace(); throw new NextSqlException("SQL Exception: " + e.getMessage(), e); } return new DBInfo(info, tables, procedures, keywords); }
From source file:telephony.test.TestDatabaseConnectionFactory.java
@Override public IDatabaseConnection createConnection(final Connection con, final DatabaseMetaData databaseMetaData) throws SQLException, DatabaseUnitException { logger.warn(String.format(">>>>> %s invoked to create a connection!\n", this.getClass().getSimpleName())); IDatabaseConnection connection = null; // FIXME not nice I found not a fast possibility to generate inside H2 // the tables inside a // schema as oracle do. final String driverName = databaseMetaData.getDriverName(); if (driverName.toLowerCase().contains("oracle")) { // oracle schema name is the user name connection = new DatabaseConnection(con, databaseMetaData.getUserName().toUpperCase()); } else {//from ww w . ja va 2 s . c o m if (driverName.contains("H2")) { // H2 connection = new DatabaseConnection(con); } else if (driverName.contains("postgresql")) { // postgresql connection = new DatabaseConnection(con, "public"); } else { // all other connection = new DatabaseConnection(con); } } logger.warn( String.format("<<<<< %s returns connection %s!\n", this.getClass().getSimpleName(), connection)); // final DatabaseConfig config = connection.getConfig(); // // oracle 10g // // FIXME at the moment we have a hard coded oracle notation // config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new // Oracle10DataTypeFactory()); return connection; }