Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
ChenShuai1981 opened this issue Oct 9, 2024 · 5 comments
Closed
2 tasks done

Comments

@ChenShuai1981
Copy link

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
@szarnyasg
Copy link
Contributor

Hi, the Brew installation, which contains the CLI client, is independent of the Java package of DuckDB. The problem may be the version of macOS – we do not officially support MacOS 10.15 and DuckDB is only tested on macOS latest.

@szarnyasg szarnyasg transferred this issue from duckdb/duckdb Oct 9, 2024
@sonofab1rd
Copy link

sonofab1rd commented Dec 11, 2024

Hello,

I'm getting a similar error:
Exception in thread "pool-4-thread-10" java.lang.NoClassDefFoundError: Could not initialize class org.duckdb.DuckDBNative
at org.duckdb.DuckDBConnection.newConnection(DuckDBConnection.java:51)
at org.duckdb.DuckDBDriver.connect(DuckDBDriver.java:41)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:683)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:253)
at com.opm.filerepair.MarthasVineyard.call(MarthasVineyard.java:28)
at com.ops.opm.entities.PatientParser.fixIncomingFile(PatientParser.java:890)
at com.ops.opm.entities.PatientParser.getHeaders(PatientParser.java:743)
at com.ops.opm.entities.PatientParser.parse(PatientParser.java:796)
at com.fkc.jcm.opm.mgenericupload.processFile(mgenericupload.java:250)
at com.fkc.html.OPSPage.start(OPSPage.java:38)
at com.fkc.httpd.httpConnection.runServlet(httpConnection.java:1142)
at com.fkc.httpd.httpConnection.runClass(httpConnection.java:1123)
at com.fkc.httpd.httpConnection.runClass(httpConnection.java:1111)
at com.fkc.httpd.httpConnection.handleRequest(httpConnection.java:412)
at com.fkc.httpd.Worker.handleClient(Worker.java:343)
at com.fkc.httpd.Worker.run(Worker.java:288)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.UnsatisfiedLinkError: /tmp/libduckdb_java9537358584425678347.so: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /tmp/libduckdb_java9537358584425678347.so) [in thread "pool-4-thread-1"]
at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:331)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:197)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:139)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2418)
at java.base/java.lang.Runtime.load0(Runtime.java:852)
at java.base/java.lang.System.load(System.java:2025)
at org.duckdb.DuckDBNative.(DuckDBNative.java:58)
... 19 more

Class.forName("org.duckdb.DuckDBDriver");
DuckDBConnection conn = (DuckDBConnection)DriverManager.getConnection("jdbc:duckdb:");
Statement stmt = conn.createStatement();

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

The application is running on docker on an AWS EC2 instance. That image is currently built
FROM public.ecr.aws/docker/library/eclipse-temurin:21-alpine

It was previously built
FROM anapsix/alpine-java:8u172b11_jdk

DuckDB worked without error on the Java8 version. However it is not working on the Java21 version.

I'm assuming that the 21-aipine image does not contain the library in the error message. Which I think is libc6-compat?

I'm going to try to add the libc6-compat to the image and see if that fixes the error.

@Mause
Copy link
Member

Mause commented Dec 13, 2024

We don't officially support alpine linux/musl based linuxes with the java bindings, any support there is best effort

@Mause Mause closed this as not planned Won't fix, can't repro, duplicate, stale Dec 13, 2024
@sonofab1rd
Copy link

Thanks @Mause! For anyone who might stumble upon this, adding a libc compat didn't work for me. I was able to switch to using the temurin:21 image that uses glibc and that worked!

@viviakemik
Copy link

hello! I'm also having the same error as java.lang.NoClassDefFoundError: Could not initialize class org.duckdb.DuckDBNative and java.lang.UnsatisfiedLinkError: C:\test\apache-tomcat-9.0.1\temp\libduckdb_java6430303658981519090.so: Can 't find dependent libraries. I use duckdb in a web application that is installed on a tomcat and the error only occurs when I install it on a virtual machine in the cloud (in the case of Azure). The machine has the Intel(R) Xeon(R) Platinum 8171M CPU @ 2.60GHz 2.10 GHz and uses Windows Server 2022 Datacenter Azure Edition. Is there anything I can do to avoid this error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants