A bundled JDBC driver for Apache Flink SQL that packages the JDBC driver implementation along with its dependencies into a single JAR file
—
Comprehensive database metadata functionality for discovering available catalogs, schemas, and database capabilities with specific Flink SQL Gateway integration. Provides detailed information about the Flink database system and its supported features.
FlinkDatabaseMetaData provides comprehensive information about the Flink database system, driver version, and capabilities.
public class FlinkDatabaseMetaData extends BaseDatabaseMetaData {
// Connection access
public Connection getConnection() throws SQLException;
// Database product information
public String getDatabaseProductName() throws SQLException; // Returns "Apache Flink"
public String getDatabaseProductVersion() throws SQLException;
public int getDatabaseMajorVersion() throws SQLException;
public int getDatabaseMinorVersion() throws SQLException;
// Driver information
public String getDriverName() throws SQLException;
public String getDriverVersion() throws SQLException;
public int getDriverMajorVersion();
public int getDriverMinorVersion();
// Connection information
public String getURL() throws SQLException;
public String getUserName() throws SQLException; // May return null
}Usage Example:
Connection connection = DriverManager.getConnection("jdbc:flink://localhost:8083");
DatabaseMetaData metadata = connection.getMetaData();
System.out.println("Database: " + metadata.getDatabaseProductName());
System.out.println("Database Version: " + metadata.getDatabaseProductVersion());
System.out.println("Driver: " + metadata.getDriverName());
System.out.println("Driver Version: " + metadata.getDriverVersion());
System.out.println("JDBC URL: " + metadata.getURL());
System.out.printf("Database Version: %d.%d%n",
metadata.getDatabaseMajorVersion(),
metadata.getDatabaseMinorVersion());Discover available catalogs and schemas in the Flink SQL Gateway environment.
public class FlinkDatabaseMetaData extends BaseDatabaseMetaData {
public ResultSet getCatalogs() throws SQLException;
public ResultSet getSchemas() throws SQLException;
public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException; // Not supported
}Catalog Discovery:
DatabaseMetaData metadata = connection.getMetaData();
ResultSet catalogs = metadata.getCatalogs();
System.out.println("Available Catalogs:");
while (catalogs.next()) {
String catalogName = catalogs.getString("TABLE_CAT");
System.out.println(" - " + catalogName);
}
catalogs.close();Schema Discovery:
DatabaseMetaData metadata = connection.getMetaData();
ResultSet schemas = metadata.getSchemas();
System.out.println("Available Schemas:");
while (schemas.next()) {
String schemaName = schemas.getString("TABLE_SCHEM");
String catalogName = schemas.getString("TABLE_CATALOG");
System.out.printf(" - %s (catalog: %s)%n", schemaName, catalogName);
}
schemas.close();Query database capabilities and supported SQL features for application compatibility.
public class FlinkDatabaseMetaData extends BaseDatabaseMetaData {
// General capabilities
public boolean isReadOnly() throws SQLException; // Returns true
public boolean allTablesAreSelectable() throws SQLException; // Returns true
public boolean allProceduresAreCallable() throws SQLException; // Returns false
// Null handling
public boolean nullsAreSortedLow() throws SQLException; // Returns true
public boolean nullsAreSortedHigh() throws SQLException; // Returns false
public boolean nullsAreSortedAtStart() throws SQLException; // Returns false
public boolean nullsAreSortedAtEnd() throws SQLException; // Returns false
// Transaction support
public boolean supportsTransactions() throws SQLException; // Returns false
public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException; // Returns false
public boolean supportsDataManipulationTransactionsOnly() throws SQLException; // Returns false
public boolean dataDefinitionCausesTransactionCommit() throws SQLException; // Returns false
public boolean dataDefinitionIgnoredInTransactions() throws SQLException; // Returns false
// Advanced features (most return false)
public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException; // Returns false
public boolean autoCommitFailureClosesAllResultSets() throws SQLException; // Returns false
public boolean generatedKeyAlwaysReturned() throws SQLException; // Returns false
}Usage Example:
DatabaseMetaData metadata = connection.getMetaData();
System.out.println("Database Capabilities:");
System.out.println(" Read-only: " + metadata.isReadOnly());
System.out.println(" Supports transactions: " + metadata.supportsTransactions());
System.out.println(" All tables selectable: " + metadata.allTablesAreSelectable());
System.out.println(" Nulls sorted low: " + metadata.nullsAreSortedLow());
System.out.println(" Supports stored procedures: " + metadata.supportsStoredFunctionsUsingCallSyntax());Query support for various SQL language features and syntax elements.
public class FlinkDatabaseMetaData extends BaseDatabaseMetaData {
// SQL syntax support
public boolean supportsANSI92EntryLevelSQL() throws SQLException;
public boolean supportsANSI92IntermediateSQL() throws SQLException;
public boolean supportsANSI92FullSQL() throws SQLException;
// JOIN support
public boolean supportsOuterJoins() throws SQLException;
public boolean supportsFullOuterJoins() throws SQLException;
public boolean supportsLimitedOuterJoins() throws SQLException;
// Subquery support
public boolean supportsCorrelatedSubqueries() throws SQLException;
public boolean supportsSubqueriesInComparisons() throws SQLException;
public boolean supportsSubqueriesInExists() throws SQLException;
public boolean supportsSubqueriesInIns() throws SQLException;
public boolean supportsSubqueriesInQuantifieds() throws SQLException;
// GROUP BY support
public boolean supportsGroupBy() throws SQLException;
public boolean supportsGroupByUnrelated() throws SQLException;
public boolean supportsGroupByBeyondSelect() throws SQLException;
// ORDER BY support
public boolean supportsOrderByUnrelated() throws SQLException;
// UNION support
public boolean supportsUnion() throws SQLException;
public boolean supportsUnionAll() throws SQLException;
}Usage Example:
DatabaseMetaData metadata = connection.getMetaData();
System.out.println("SQL Feature Support:");
System.out.println(" ANSI SQL 92 Entry Level: " + metadata.supportsANSI92EntryLevelSQL());
System.out.println(" Outer Joins: " + metadata.supportsOuterJoins());
System.out.println(" Full Outer Joins: " + metadata.supportsFullOuterJoins());
System.out.println(" Correlated Subqueries: " + metadata.supportsCorrelatedSubqueries());
System.out.println(" GROUP BY: " + metadata.supportsGroupBy());
System.out.println(" UNION: " + metadata.supportsUnion());
System.out.println(" UNION ALL: " + metadata.supportsUnionAll());Information about identifier quoting, case sensitivity, and string handling.
public class FlinkDatabaseMetaData extends BaseDatabaseMetaData {
// Identifier handling
public String getIdentifierQuoteString() throws SQLException; // Returns "`"
public boolean supportsMixedCaseIdentifiers() throws SQLException; // Returns true
public boolean storesMixedCaseIdentifiers() throws SQLException; // Returns true
public boolean storesUpperCaseIdentifiers() throws SQLException; // Returns false
public boolean storesLowerCaseIdentifiers() throws SQLException; // Returns false
public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException;
public boolean storesMixedCaseQuotedIdentifiers() throws SQLException;
public boolean storesUpperCaseQuotedIdentifiers() throws SQLException;
public boolean storesLowerCaseQuotedIdentifiers() throws SQLException;
// String functions and literals
public String getStringFunctions() throws SQLException;
public String getNumericFunctions() throws SQLException;
public String getTimeDateFunctions() throws SQLException;
public String getSystemFunctions() throws SQLException;
public String getSQLKeywords() throws SQLException;
}Usage Example:
DatabaseMetaData metadata = connection.getMetaData();
System.out.println("Identifier Handling:");
System.out.println(" Quote string: '" + metadata.getIdentifierQuoteString() + "'");
System.out.println(" Mixed case identifiers: " + metadata.supportsMixedCaseIdentifiers());
System.out.println(" Stores mixed case: " + metadata.storesMixedCaseIdentifiers());
// Use quoted identifiers when needed
Statement stmt = connection.createStatement();
ResultSet results = stmt.executeQuery("SELECT `Column Name` FROM `My Table`");Information about supported data types and their characteristics.
public class FlinkDatabaseMetaData extends BaseDatabaseMetaData {
public ResultSet getTypeInfo() throws SQLException; // Not fully implemented
// Numeric limits
public int getMaxBinaryLiteralLength() throws SQLException;
public int getMaxCharLiteralLength() throws SQLException;
public int getMaxColumnNameLength() throws SQLException;
public int getMaxColumnsInGroupBy() throws SQLException;
public int getMaxColumnsInIndex() throws SQLException;
public int getMaxColumnsInOrderBy() throws SQLException;
public int getMaxColumnsInSelect() throws SQLException;
public int getMaxColumnsInTable() throws SQLException;
public int getMaxConnections() throws SQLException;
public int getMaxCursorNameLength() throws SQLException;
public int getMaxIndexLength() throws SQLException;
public int getMaxSchemaNameLength() throws SQLException;
public int getMaxProcedureNameLength() throws SQLException;
public int getMaxCatalogNameLength() throws SQLException;
public int getMaxRowSize() throws SQLException;
public int getMaxStatementLength() throws SQLException;
public int getMaxStatements() throws SQLException;
public int getMaxTableNameLength() throws SQLException;
public int getMaxTablesInSelect() throws SQLException;
public int getMaxUserNameLength() throws SQLException;
}Transaction isolation and locking information (mostly not applicable to Flink).
public class FlinkDatabaseMetaData extends BaseDatabaseMetaData {
public int getDefaultTransactionIsolation() throws SQLException; // Returns TRANSACTION_NONE
public boolean supportsTransactionIsolationLevel(int level) throws SQLException; // Returns false
public boolean supportsResultSetType(int type) throws SQLException;
public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException;
public boolean supportsResultSetHoldability(int holdability) throws SQLException;
public int getResultSetHoldability() throws SQLException;
public int getSQLStateType() throws SQLException;
public boolean locatorsUpdateCopy() throws SQLException;
}The following metadata operations are not supported and will throw exceptions:
// Table and column metadata (throw UnsupportedOperationException)
public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException;
public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException;
public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException;
public ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException;
public ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException;
public ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException;
public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException;
// Stored procedures and functions
public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException;
public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException;
public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) throws SQLException;
public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) throws SQLException;
// User-defined types
public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException;
// Privileges
public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) throws SQLException;
public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) throws SQLException;
// Version columns and best row identifier
public ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException;
public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) throws SQLException;
// Attributes and super types/tables
public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) throws SQLException;
public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) throws SQLException;
public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException;
// Client info properties
public ResultSet getClientInfoProperties() throws SQLException;
// Pseudo columns
public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException;Supporting utility classes for metadata operations:
public class DatabaseMetaDataUtils {
public static FlinkResultSet createCatalogsResultSet(Statement statement, StatementResult result);
public static FlinkResultSet createSchemasResultSet(Statement statement, List<String> catalogs, Map<String, List<String>> catalogSchemas);
}Common metadata access errors:
Connection Required:
DatabaseMetaData metadata = connection.getMetaData();
connection.close();
try {
metadata.getCatalogs(); // May fail if connection is closed
} catch (SQLException e) {
System.err.println("Connection closed: " + e.getMessage());
}Unsupported Operations:
try {
metadata.getTables(null, null, "%", null);
} catch (UnsupportedOperationException e) {
System.err.println("Table metadata not supported: " + e.getMessage());
}Network Issues:
try {
ResultSet catalogs = metadata.getCatalogs();
} catch (SQLException e) {
System.err.println("Failed to retrieve catalogs: " + e.getMessage());
// May need to retry with a new connection
}Application Compatibility Check:
public boolean isFlinkCompatible(Connection connection) throws SQLException {
DatabaseMetaData metadata = connection.getMetaData();
// Check if it's actually Flink
if (!"Apache Flink".equals(metadata.getDatabaseProductName())) {
return false;
}
// Check required capabilities
if (!metadata.supportsGroupBy()) {
return false;
}
if (!metadata.supportsUnion()) {
return false;
}
return true;
}Dynamic Schema Discovery:
public void discoverSchema(Connection connection) throws SQLException {
DatabaseMetaData metadata = connection.getMetaData();
// List all catalogs
System.out.println("Available catalogs:");
try (ResultSet catalogs = metadata.getCatalogs()) {
while (catalogs.next()) {
String catalog = catalogs.getString("TABLE_CAT");
System.out.println(" " + catalog);
}
}
// List all schemas
System.out.println("Available schemas:");
try (ResultSet schemas = metadata.getSchemas()) {
while (schemas.next()) {
String schema = schemas.getString("TABLE_SCHEM");
String catalog = schemas.getString("TABLE_CATALOG");
System.out.printf(" %s.%s%n", catalog, schema);
}
}
}Connection Information Display:
public void displayConnectionInfo(Connection connection) throws SQLException {
DatabaseMetaData metadata = connection.getMetaData();
System.out.println("=== Connection Information ===");
System.out.printf("Database: %s %s%n",
metadata.getDatabaseProductName(),
metadata.getDatabaseProductVersion());
System.out.printf("Driver: %s %s%n",
metadata.getDriverName(),
metadata.getDriverVersion());
System.out.printf("URL: %s%n", metadata.getURL());
System.out.printf("Read-only: %s%n", metadata.isReadOnly());
System.out.printf("Supports transactions: %s%n", metadata.supportsTransactions());
System.out.printf("Quote string: '%s'%n", metadata.getIdentifierQuoteString());
}Install with Tessl CLI
npx tessl i tessl/maven-org-apache-flink--flink-sql-jdbc-driver-bundle