CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-apache-flink--flink-sql-jdbc-driver-bundle

A bundled JDBC driver for Apache Flink SQL that packages the JDBC driver implementation along with its dependencies into a single JAR file

Pending
Overview
Eval results
Files

connection-management.mddocs/

Driver Registration and Connection Management

Comprehensive JDBC driver functionality for connecting to Apache Flink SQL Gateway, including automatic driver registration, URL parsing, and connection lifecycle management with catalog and schema support.

Capabilities

Driver Registration

The Flink JDBC driver automatically registers itself with the JDBC DriverManager through the standard META-INF/services mechanism, enabling standard JDBC connection patterns.

public class FlinkDriver implements Driver {
    // Automatic registration via static block
    static {
        try {
            DriverManager.registerDriver(new FlinkDriver());
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    
    public Connection connect(String url, Properties driverProperties) throws SQLException;
    public boolean acceptsURL(String url) throws SQLException;
    public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException;
    public int getMajorVersion();
    public int getMinorVersion();
    public boolean jdbcCompliant(); // Returns false - not fully JDBC compliant
    public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException;
}

Usage Example:

// Driver is automatically registered - no manual registration needed
String url = "jdbc:flink://localhost:8083";
Connection conn = DriverManager.getConnection(url);

DataSource Implementation

FlinkDataSource provides a DataSource implementation for connection pooling scenarios and framework integration.

public class FlinkDataSource implements DataSource {
    public FlinkDataSource(String url, Properties properties);
    
    public Connection getConnection() throws SQLException;
    public Connection getConnection(String username, String password) throws SQLException; // Not supported
    
    // Standard DataSource methods (most not supported)
    public <T> T unwrap(Class<T> iface) throws SQLException; // Not supported
    public boolean isWrapperFor(Class<?> iface) throws SQLException; // Not supported
    public PrintWriter getLogWriter() throws SQLException; // Not supported
    public void setLogWriter(PrintWriter out) throws SQLException; // Not supported
    public void setLoginTimeout(int seconds) throws SQLException; // Not supported
    public int getLoginTimeout() throws SQLException; // Not supported
    public Logger getParentLogger() throws SQLFeatureNotSupportedException; // Not supported
}

Usage Example:

Properties props = new Properties();
props.setProperty("catalog", "my_catalog");
props.setProperty("database", "my_database");

FlinkDataSource dataSource = new FlinkDataSource(
    "jdbc:flink://localhost:8083", 
    props
);

Connection connection = dataSource.getConnection();

Connection Implementation

FlinkConnection provides the core connection functionality to Flink SQL Gateway with catalog and schema management.

public class FlinkConnection extends BaseConnection {
    public FlinkConnection(DriverUri driverUri);
    
    // Statement creation
    public Statement createStatement() throws SQLException;
    
    // Transaction management (limited support)
    public void setAutoCommit(boolean autoCommit) throws SQLException; // No-op for compatibility
    public boolean getAutoCommit() throws SQLException; // Always returns true
    public void setTransactionIsolation(int level) throws SQLException; // No-op for compatibility
    public int getTransactionIsolation() throws SQLException; // Returns TRANSACTION_NONE
    
    // Connection lifecycle
    public void close() throws SQLException;
    public boolean isClosed() throws SQLException;
    
    // Metadata access
    public DatabaseMetaData getMetaData() throws SQLException;
    
    // Catalog and schema management
    public void setCatalog(String catalog) throws SQLException;
    public String getCatalog() throws SQLException;
    public void setSchema(String schema) throws SQLException;
    public String getSchema() throws SQLException;
    
    // Client information
    public void setClientInfo(String name, String value) throws SQLClientInfoException;
    public void setClientInfo(Properties properties) throws SQLClientInfoException;
    public String getClientInfo(String name) throws SQLException;
    public Properties getClientInfo() throws SQLException;
    
    // Warnings (not supported)
    public SQLWarning getWarnings() throws SQLException; // Returns null
    public void clearWarnings() throws SQLException; // No-op
}

Important: FlinkConnection is NOT thread-safe. Use separate connections for each thread.

Usage Example:

String url = "jdbc:flink://localhost:8083/my_catalog/my_database";
Connection connection = DriverManager.getConnection(url);

// Set catalog and schema
connection.setCatalog("production_catalog");
connection.setSchema("analytics_schema");

// Get current catalog and schema
String currentCatalog = connection.getCatalog();
String currentSchema = connection.getSchema();

URL Parsing and Configuration

DriverUri handles parsing and validation of Flink JDBC URLs with comprehensive property support.

public class DriverUri {
    public static DriverUri create(String url, Properties properties) throws SQLException;
    public static boolean acceptsURL(String url);
    
    public InetSocketAddress getAddress();
    public Properties getProperties();
    public Optional<String> getCatalog();
    public Optional<String> getDatabase();
    public String getURL();
}

URL Format: jdbc:flink://host:port[/catalog[/database]][?param=value&...]

URL Examples:

  • jdbc:flink://localhost:8083 - Basic connection
  • jdbc:flink://flink-gateway:8083/my_catalog - With catalog
  • jdbc:flink://flink-gateway:8083/my_catalog/my_database - With catalog and database
  • jdbc:flink://localhost:8083?timeout=30000&retries=3 - With query parameters

Usage Example:

String url = "jdbc:flink://localhost:8083/production/analytics?timeout=30000";
Properties props = new Properties();
props.setProperty("user", "analytics_user");

DriverUri driverUri = DriverUri.create(url, props);
InetSocketAddress address = driverUri.getAddress(); // localhost:8083
Optional<String> catalog = driverUri.getCatalog(); // "production"
Optional<String> database = driverUri.getDatabase(); // "analytics"
Properties allProps = driverUri.getProperties(); // Includes timeout and user

Unsupported Connection Features

The following standard JDBC connection features are not supported and will throw SQLFeatureNotSupportedException:

  • Prepared Statements: prepareStatement() methods
  • Callable Statements: prepareCall() methods
  • Transactions: commit(), rollback(), setSavepoint(), releaseSavepoint()
  • Type Maps: setTypeMap(), getTypeMap()
  • Holdability: setHoldability(), getHoldability()
  • Network Timeout: setNetworkTimeout(), getNetworkTimeout()
  • Abort: abort()
  • Array/Struct/Blob/Clob Creation: createArrayOf(), createStruct(), etc.

Connection Properties

Supported connection properties can be passed via the Properties parameter or as URL query parameters:

  • catalog: Default catalog to use
  • database: Default database/schema to use
  • Custom properties are passed through to the underlying Flink SQL Gateway connection

Example with Properties:

Properties props = new Properties();
props.setProperty("catalog", "production");
props.setProperty("database", "analytics");
props.setProperty("timeout", "30000");

Connection conn = DriverManager.getConnection(
    "jdbc:flink://localhost:8083", 
    props
);

Error Handling

Connection-related operations may throw:

  • SQLException: For general connection errors, invalid URLs, or connection failures
  • SQLFeatureNotSupportedException: For unsupported JDBC features
  • SQLClientInfoException: For client info operations that cannot be applied

Common error scenarios:

  • Invalid URL format: jdbc:invalid://localhost:8083
  • Connection timeout: Server not responding
  • Authentication failures: Invalid credentials
  • Network connectivity issues: Host unreachable

Install with Tessl CLI

npx tessl i tessl/maven-org-apache-flink--flink-sql-jdbc-driver-bundle

docs

connection-management.md

database-metadata.md

index.md

result-set-processing.md

statement-execution.md

tile.json