A bundled JDBC driver for Apache Flink SQL that packages the JDBC driver implementation along with its dependencies into a single JAR file
—
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.
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);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();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();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 connectionjdbc:flink://flink-gateway:8083/my_catalog - With catalogjdbc:flink://flink-gateway:8083/my_catalog/my_database - With catalog and databasejdbc:flink://localhost:8083?timeout=30000&retries=3 - With query parametersUsage 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 userThe following standard JDBC connection features are not supported and will throw SQLFeatureNotSupportedException:
prepareStatement() methodsprepareCall() methodscommit(), rollback(), setSavepoint(), releaseSavepoint()setTypeMap(), getTypeMap()setHoldability(), getHoldability()setNetworkTimeout(), getNetworkTimeout()abort()createArrayOf(), createStruct(), etc.Supported connection properties can be passed via the Properties parameter or as URL query parameters:
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
);Connection-related operations may throw:
Common error scenarios:
jdbc:invalid://localhost:8083Install with Tessl CLI
npx tessl i tessl/maven-org-apache-flink--flink-sql-jdbc-driver-bundle