Skip to main content

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:

  1. Environment variable motherduck_token

  2. Passing the token as a connection string parameter:

Connection conn = DriverManager.getConnection("jdbc:duckdb:md:my_db?motherduck_token="+token);
  1. Interactive authentication through a web browser.

See Authenticating to MotherDuck for more details.