Skip to content

Instance caching prevents multiple connections, closing and re-opening with JDBC #5371

@paulewog

Description

@paulewog

What happens?

It looks like the instance caching is failing to allow either multiple connections, or closing the connection and subsequently opening the database again.

To Reproduce

This throws an error:

import java.sql.Connection;
import java.sql.DriverManager;

class duckdb {
    public static void main(String[] args) {
        try {
            Connection conn = DriverManager.getConnection("jdbc:duckdb:test-temp.db");
            Connection conn2 = DriverManager.getConnection("jdbc:duckdb:test-temp.db");

            conn.close();
            conn2.close();
        } catch (Exception e) {
            System.out.println(e);
            e.printStackTrace();
        }
    }
}

The error thrown:

java.sql.SQLException: Connection Error: Instance with path: /Users/pellsworth/test-duckdb/test-temp.db already exists.
	at org.duckdb.DuckDBNative.duckdb_jdbc_startup(Native Method)
	at org.duckdb.DuckDBDatabase.<init>(DuckDBDatabase.java:28)
	at org.duckdb.DuckDBDriver.connect(DuckDBDriver.java:36)
	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:251)
	at duckdb.main(duckdb.java:8)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at jdk.compiler/com.sun.tools.javac.launcher.Main.execute(Main.java:404)
	at jdk.compiler/com.sun.tools.javac.launcher.Main.run(Main.java:179)
	at jdk.compiler/com.sun.tools.javac.launcher.Main.main(Main.java:119)

(it also will throw the same error if you try to close the first connection before opening the second).

OS:

OSX, x64

DuckDB Version:

0.6.0

DuckDB Client:

Java

Full Name:

Paul Ellsworth

Affiliation:

Tenable

Have you tried this on the latest master branch?

  • I agree

Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?

  • I agree

Metadata

Metadata

Assignees

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