Arrow Flight SQL: Java (Flight SQL JDBC driver)
The only change
Section titled “The only change”# URI grpc+tls://flight.internal:32010 grpc+tls://warehouse.internal:32010# user / password (or token) the server's account MachWarehouse accountJDBC URL: jdbc:arrow-flight-sql://warehouse.internal:32010/?useEncryption=true. The same driver serves DBeaver, Tableau and other JDBC tools. On Java 17+ the Arrow memory module needs --add-opens=java.base/java.nio=ALL-UNNAMED (set it in MAVEN_OPTS or the tool’s JVM options).
MAVEN_OPTS="--add-opens=java.base/java.nio=ALL-UNNAMED" mvn -q compile exec:javaLibrary: org.apache.arrow:flight-sql-jdbc-driver 19.0.0, Java 25 LTS.
Source
Section titled “Source”The program as it is kept and tested in the Mach Database Warehouse repository; highlighted lines read the connection setting.
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>example.machwarehouse</groupId> <artifactId>flight-sql-jdbc-example</artifactId> <version>1.0.0</version> <properties> <maven.compiler.release>25</maven.compiler.release> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <exec.mainClass>example.Main</exec.mainClass> </properties> <dependencies> <dependency> <groupId>org.apache.arrow</groupId> <artifactId>flight-sql-jdbc-driver</artifactId> <version>19.0.0</version> </dependency> </dependencies></project>package example;
import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;import java.util.Properties;
/** Runs a query through the Arrow Flight SQL JDBC driver. Plain JDBC code. */public final class Main { private Main() {}
public static void main(String[] args) throws Exception { // Before: jdbc:arrow-flight-sql://flight.internal:32010/?useEncryption=true // After: jdbc:arrow-flight-sql://warehouse.internal:32010/?useEncryption=true String url = System.getenv("FLIGHT_SQL_JDBC_URL"); Properties props = new Properties(); props.setProperty("user", System.getenv("FLIGHT_SQL_USER")); props.setProperty("password", System.getenv("FLIGHT_SQL_PASSWORD")); try (Connection conn = DriverManager.getConnection(url, props); Statement st = conn.createStatement(); ResultSet rs = st.executeQuery( "SELECT country, count(*) AS events, sum(revenue) AS revenue FROM events GROUP BY country ORDER BY revenue DESC")) { while (rs.next()) { System.out.printf("%s\t%d\t%s%n", rs.getString(1), rs.getLong(2), rs.getBigDecimal(3)); } } }}