@Override public ResultSet getCatalogs() throws SQLException { return metaData.getCatalogs(); }
@Override public Set<String> getSchemaNames() { // for MySQL, we need to list catalogs instead of schemas try (Connection connection = connectionFactory.openConnection(); ResultSet resultSet = connection.getMetaData().getCatalogs()) { ImmutableSet.Builder<String> schemaNames = ImmutableSet.builder(); while (resultSet.next()) { String schemaName = resultSet.getString("TABLE_CAT").toLowerCase(ENGLISH); // skip internal schemas if (!schemaName.equals("information_schema") && !schemaName.equals("mysql")) { schemaNames.add(schemaName); } } return schemaNames.build(); } catch (SQLException e) { throw new RuntimeException(e); } }
/** * Get the names of all of the catalogs. * @return the set of catalog names; never null but possibly empty * @throws SQLException if an error occurs while accessing the database metadata */ public Set<String> readAllCatalogNames() throws SQLException { Set<String> catalogs = new HashSet<>(); DatabaseMetaData metadata = connection().getMetaData(); try (ResultSet rs = metadata.getCatalogs()) { while (rs.next()) { String catalogName = rs.getString(1); catalogs.add(catalogName); } } return catalogs; }
String getCatalogNameFromMetaData(DatabaseMetaData metaData, RegionMapping regionMapping) throws SQLException { String catalogFilter = regionMapping.getCatalog(); if (catalogFilter == null || catalogFilter.isEmpty()) { return DEFAULT_CATALOG; } try (ResultSet catalogs = metaData.getCatalogs()) { return findMatchInResultSet(catalogFilter, catalogs, "TABLE_CAT", "catalog"); } }
@Override public ResultSet getResult(Connection c) throws SQLException { return c.getMetaData().getCatalogs(); } }, 1);
@Override public boolean catalogExists(Identifier catalog) { try { final ResultSet resultSet = extractionContext.getJdbcDatabaseMetaData().getCatalogs(); try { while ( resultSet.next() ) { final String existingCatalogName = resultSet.getString( "TABLE_CAT" ); // todo : hmm.. case sensitive or insensitive match... // for now, match any case... if ( catalog.getText().equalsIgnoreCase( existingCatalogName ) ) { return true; } } return false; } finally { try { resultSet.close(); } catch (SQLException ignore) { } } } catch (SQLException sqlException) { throw convertSQLException( sqlException, "Unable to query DatabaseMetaData for existing catalogs" ); } }
public String[] getCatalogs() throws KettleDatabaseException { ArrayList<String> catalogList = new ArrayList<String>(); ResultSet catalogResultSet = null; try { catalogResultSet = getDatabaseMetaData().getCatalogs(); // Grab all the catalog names and put them in an array list while ( catalogResultSet != null && catalogResultSet.next() ) { catalogList.add( catalogResultSet.getString( 1 ) ); } } catch ( SQLException e ) { throw new KettleDatabaseException( "Error getting catalogs!", e ); } finally { try { if ( catalogResultSet != null ) { catalogResultSet.close(); } } catch ( SQLException e ) { throw new KettleDatabaseException( "Error closing resultset after getting catalogs!", e ); } } if ( log.isDetailed() ) { log.logDetailed( "read :" + catalogList.size() + " catalogs from db meta-data." ); } return catalogList.toArray( new String[ catalogList.size() ] ); }
public JdbcCatalogSchema(String name) { super(Collections.emptyList(), name); try (Connection con = source.getConnection(); ResultSet set = con.getMetaData().getCatalogs()) { while (set.next()) { final String catalogName = set.getString(1); CapitalizingJdbcSchema schema = new CapitalizingJdbcSchema( getSchemaPath(), catalogName, source, dialect, convention, catalogName, null); schemaMap.put(schema.getName(), schema); } } catch (SQLException e) { logger.warn("Failure while attempting to load JDBC schema.", e); } // unable to read catalog list. if (schemaMap.isEmpty()) { // try to add a list of schemas to the schema map. boolean schemasAdded = addSchemas(); if (!schemasAdded) { // there were no schemas, just create a default one (the jdbc system doesn't support catalogs/schemas). schemaMap.put(SchemaFactory.DEFAULT_WS_NAME, new CapitalizingJdbcSchema(Collections.emptyList(), name, source, dialect, convention, null, null)); } } else { // We already have catalogs. Add schemas in this context of their catalogs. addSchemas(); } defaultSchema = schemaMap.values().iterator().next(); }
@Test public void testGetCatalogs() throws Exception { try (Connection connection = createConnection()) { try (ResultSet rs = connection.getMetaData().getCatalogs()) { assertEquals(readRows(rs), list(list("blackhole"), list("system"), list(TEST_CATALOG))); ResultSetMetaData metadata = rs.getMetaData(); assertEquals(metadata.getColumnCount(), 1); assertEquals(metadata.getColumnLabel(1), "TABLE_CAT"); assertEquals(metadata.getColumnType(1), Types.VARCHAR); } } }
@Test public void getCatalogNameFromMetaDataGivenCatalogReturnIt() throws SQLException { String myCatalog = "myCatalog"; when(regionMapping.getCatalog()).thenReturn(myCatalog); ResultSet catalogsResultSet = mock(ResultSet.class); when(catalogsResultSet.next()).thenReturn(true).thenReturn(false); when(catalogsResultSet.getString("TABLE_CAT")).thenReturn(myCatalog); when(databaseMetaData.getCatalogs()).thenReturn(catalogsResultSet); String result = tableMetaDataManager.getCatalogNameFromMetaData(databaseMetaData, regionMapping); assertThat(result).isEqualTo(myCatalog); }
@Signature public Memory getCatalogs(Environment env) throws SQLException { ResultSet catalogs = metaData.getCatalogs(); ArrayMemory r = new ArrayMemory(); while (catalogs.next()) { r.add(new PSqlResult(env, catalogs).toArray(env)); } return r.toConstant(); }
@Test public void testDatabaseMetaDataCatalogs() throws Exception { final DatabaseMetaData metaData = client.getMetaData(); Assert.assertEquals( ImmutableList.of( ROW(Pair.of("TABLE_CAT", "druid")) ), getRows(metaData.getCatalogs()) ); }
Connection conn = driver.connect("jdbc:kylin://localhost:7070/default", info); ResultSet catalogs = conn.getMetaData().getCatalogs(); System.out.println("CATALOGS"); printResultSetMetaData(catalogs);
try (final ResultSet catalogResultSet = connection.getMetaData().getCatalogs()) { while (catalogResultSet.next()) { final String schemaName = catalogResultSet.getString(1);
ResultSet catalogResultSet = dbmd.getCatalogs();
@Override public ResultSet getCatalogs() throws SQLException { return metaData.getCatalogs(); }
final ResultSet catalogsResultSet = dbMetaData.getCatalogs(); assertThat( catalogsResultSet, notNullValue() ); assertThat( catalogsResultSet, instanceOf( ResultSet.class ) );
return meta.getBestRowIdentifier(p[1], p[2], p[3], scale, nullable); } else if (isBuiltIn(sql, "@catalogs")) { return meta.getCatalogs(); } else if (isBuiltIn(sql, "@columns")) { String[] p = split(sql);
Class.forName("com.mysql.jdbc.Driver"); // change user and password as you need it Connection con = DriverManager.getConnection (connectionURL, "user", "password"); ResultSet rs = con.getMetaData().getCatalogs(); while (rs.next()) { System.out.println("TABLE_CAT = " + rs.getString("TABLE_CAT") ); }
@Test public void testCatalogs() throws Exception { try (final Connection connection = DriverManager.getConnection(CONN_STRING)) { assertThat(connection.isClosed(), is(false)); try (final ResultSet resultSet = connection.getMetaData().getCatalogs()) { final ResultSetMetaData metaData = resultSet.getMetaData(); assertFalse("unexpected populated resultSet", resultSet.next()); assertEquals(1, metaData.getColumnCount()); assertEquals(TABLE_CAT, metaData.getColumnName(1)); } } }