Skip to content

About

DuckDB JDBC Driver

Topics

Resources

Code of conduct

Stars

129 stars

Watchers

9 watching

Forks

Repository files navigation

Two JDKs are used by the build, they can be the same one:

  • JAVA_JNI (JDK 8 or later) compiles the driver, the JNI bindings and the tests. It is the JDK in the JAVA_JNI_HOME environment variable, otherwise the JDK that CMake detects (JAVA_HOME).
  • JAVA_FFM (JDK 25 or later) compiles the FFM bindings. It is the JDK in the JAVA_FFM_HOME environment variable, otherwise JAVA_JNI. The build fails to configure when it is older than JDK 25 or older than JAVA_JNI.

The class files have the version of the JDK that compiles them: the driver runs on the JDK of JAVA_JNI and later ones, and it uses the FFM bindings on the JDK of JAVA_FFM and later ones. Release builds use JDK 8 and JDK 25, CMake warns about other versions.

Development

To build the driver, run make release.

This will produce two jars in the build folder: build/release/duckdb_jdbc.jar build/release/duckdb_jdbc_tests.jar

The tests can be ran using using make test or this command

java -cp "build/release/duckdb_jdbc_tests.jar:build/release/duckdb_jdbc.jar" org/duckdb/TestDuckDBJDBC

This optionally takes an argument to only run a single test, for example:

java -cp "build/release/duckdb_jdbc_tests.jar:build/release/duckdb_jdbc.jar"  org/duckdb/TestDuckDBJDBC test_valid_but_local_config_throws_exception

The string write performance benchmark is optional and can be run with:

make stress

Override its workload with PERF_ROWS and PERF_SAMPLES if needed. The benchmark is intentionally not part of the regular test suite.

Scalar function usage examples: UDF.MD

JFR memory monitoring usage: JFR.md

Java 25+ (Foreign Function and Memory API)

Both duckdb_jdbc.jar and duckdb_jdbc_nolib.jar are multi-release jars. On Java 25 and later the driver calls the C API of the native library directly with the Foreign Function and Memory API (java.lang.foreign), without JNI. Older JDKs use the JNI bindings. -Djdk.util.jar.enableMultiRelease=false makes Java 25 and later use the JNI bindings too.

The classes of the FFM bindings are in src/main/java22. They are compiled with JAVA_FFM (see above) and are packed as META-INF/versions/<version of JAVA_FFM>, that is META-INF/versions/25 in release builds. The rest of the driver is compiled with JAVA_JNI.

To avoid the warning of the JDK about native access, run with --enable-native-access=ALL-UNNAMED (or --enable-native-access=duckdb.jdbc on the module path).

The symbols that the FFM bindings call are exported from the native library, scripts/update_exports.py updates the symbol lists after the C API changes, scripts/gen_ffm_native.py and scripts/gen_ffm_bindings.py generate Capi.java and DuckDBBindings.java of src/main/java22.

GraalVM Native Image: an image that is built with GraalVM for JDK 25 or later uses the FFM bindings. Their foreign calls are registered in the Native Image metadata of the driver (META-INF/native-image/org.duckdb/duckdb_jdbc/reachability-metadata.json), scripts/gen_ffm_native.py generates these registrations too. To build an image with the JNI bindings pass -J-Djdk.util.jar.enableMultiRelease=false to native-image.

About

DuckDB JDBC Driver

Topics

Resources

Code of conduct

Stars

129 stars

Watchers

9 watching

Forks

Releases

Packages

Used by

Contributors

Languages