JDBC driver
The official DuckDB JDBC driver supports MotherDuck out of the box!
To connect, you need a dependency on the driver. For example, in your Maven pom.xml file:
<dependency>
<groupId>org.duckdb</groupId>
<artifactId>duckdb_jdbc</artifactId>
<version>0.9.1</version>
</dependency>
Your code can then create a Connection
by using jdbc:duckdb:md:databaseName
connection string format:
Connection conn = DriverManager.getConnection("jdbc:duckdb:md:my_db");
This Connection
can then be used directly or through any framework built on java.sql
JDBC abstractions.
There are currently 3 ways to authenticate with a valid MotherDuck token:
-
Environment variable
motherduck_token
-
Passing the token as a connection string parameter:
Connection conn = DriverManager.getConnection("jdbc:duckdb:md:my_db?motherduck_token="+token);
- Interactive authentication through a web browser.
See Authenticating to MotherDuck for more details.