Skip to content

java.lang.UnsatisfiedLinkError when using JDBC connect DuckDB #96

@ChenShuai1981

Description

@ChenShuai1981

What happens?

When I used duckdb jdbc api to connect duckdb and fetch data, it reported the following errors
openjdk version "1.8.0_332"

Exception in thread "main" java.lang.UnsatisfiedLinkError: /private/var/folders/m4/0x7rjxjd64z2_xsvp6pdrvlw0000gn/T/libduckdb_java8670861399984197079.so: dlopen(/private/var/folders/m4/0x7rjxjd64z2_xsvp6pdrvlw0000gn/T/libduckdb_java8670861399984197079.so, 1): Symbol not found: __ZNKSt3__115basic_stringbufIcNS_11char_traitsIcEENS_9allocatorIcEEE3strEv
  Referenced from: /private/var/folders/m4/0x7rjxjd64z2_xsvp6pdrvlw0000gn/T/libduckdb_java8670861399984197079.so (which was built for Mac OS X 14.0)
  Expected in: /usr/lib/libc++.1.dylib

	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
	at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1937)
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1820)
	at java.lang.Runtime.load0(Runtime.java:782)
	at java.lang.System.load(System.java:1098)
	at org.duckdb.DuckDBNative.<clinit>(DuckDBNative.java:58)
	at org.duckdb.DuckDBConnection.newConnection(DuckDBConnection.java:51)
	at org.duckdb.DuckDBDriver.connect(DuckDBDriver.java:41)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:270)
	at Test.main(Test.java:10)

To Reproduce

The java program code

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;

public class Test {
    public static void main(String[] args) throws Exception {
        Class.forName("org.duckdb.DuckDBDriver");
        Connection conn = DriverManager.getConnection("jdbc:duckdb:~/myduckdb.db");
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT current_date");
        Date currentDate = rs.next() ? rs.getDate(1) : null;
        System.out.println(currentDate);
    }
}

The maven dependency

<dependencies>
        <dependency>
            <groupId>org.duckdb</groupId>
            <artifactId>duckdb_jdbc</artifactId>
            <version>1.1.0</version>
        </dependency>
</dependencies>

The duckdb is installed by Homebrew

$ brew install duckdb
Warning: No remote 'origin' in /usr/local/Homebrew/Library/Taps/admin/homebrew-local-tap, skipping update!
duckdb 0.3.2 is already installed but outdated (so it will be upgraded).
Warning: You are using macOS 10.15.
We (and Apple) do not provide support for this old version.
It is expected behaviour that some formulae will fail to build in this old version.
It is expected behaviour that Homebrew will be buggy and slow.
Do not create any issues about this on Homebrew's GitHub repositories.
Do not create any issues even if you think this message is unrelated.
Any opened issues will be immediately closed without response.
Do not ask for help from Homebrew or its maintainers on social media.
You may ask for help in Homebrew's discussions but are unlikely to receive a response.
Try to figure out the problem yourself and submit a fix as a pull request.
We will review it but may or may not accept it.

==> Fetching dependencies for duckdb: cmake
==> Fetching cmake
==> Downloading https://raw.githubusercontent.com/Homebrew/homebrew-core/a9e384d484c4ffbe5aa651c9e80
Already downloaded: /Users/admin/Library/Caches/Homebrew/downloads/d08a1ab5683b0543265e5b1d1ed5eaf9e5223ceb5c67ac80218ec2c1a7d20f73--cmake.rb
==> Downloading https://github.com/Kitware/CMake/releases/download/v3.30.5/cmake-3.30.5.tar.gz
==> Downloading from https://objects.githubusercontent.com/github-production-release-asset-2e65be/53
############################################################################################# 100.0%
==> Fetching duckdb
==> Downloading https://raw.githubusercontent.com/Homebrew/homebrew-core/a9e384d484c4ffbe5aa651c9e80
Already downloaded: /Users/admin/Library/Caches/Homebrew/downloads/64a2f18696e8a229cd63fb524dde2689a278527e95d420f1cf5a4ece2be49f42--duckdb.rb
==> Cloning https://github.com/duckdb/duckdb.git
Cloning into '/Users/admin/Library/Caches/Homebrew/duckdb--git'...
Updating files: 100% (12358/12358), done.
==> Checking out tag v1.1.1
HEAD is now at af39bd0dcf CIBW_SKIP also musllinux on Python 3.7 or Python 3.8 (#14074)
==> Upgrading duckdb
  0.3.2 -> 1.1.1 

==> Installing dependencies for duckdb: cmake
==> Installing duckdb dependency: cmake
==> ./bootstrap --prefix=/usr/local/Cellar/cmake/3.30.5 --no-system-libs --parallel=12 --datadir=/sh
==> make
==> make install
🍺  /usr/local/Cellar/cmake/3.30.5: 3,423 files, 61.3MB, built in 10 minutes 26 seconds
==> Installing duckdb
==> Downloading https://formulae.brew.sh/api/formula.jws.json
############################################################################################# 100.0%
==> cmake -S . -B build -DBUILD_EXTENSIONS='autocomplete;icu;parquet;json' -DENABLE_EXTENSION_AUTOLO
==> cmake --build build
==> cmake --install build
🍺  /usr/local/Cellar/duckdb/1.1.1: 1,178 files, 153.5MB, built in 7 minutes 32 seconds
==> Running `brew cleanup duckdb`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Removing: /usr/local/Cellar/duckdb/0.3.2... (696 files, 62.2MB)

$ duckdb -version
v1.1.1 af39bd0dcf

OS:

MacOS 10.15

DuckDB Version:

1.1.0

DuckDB Client:

JDBC

Hardware:

No response

Full Name:

Shuai Chen

Affiliation:

Huifu Company, China

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have not tested with any build

Did you include all relevant data sets for reproducing the issue?

No - Other reason (please specify in the issue body)

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

  • Yes, I have

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions