Empowering Data Teams: Smarter AI WorkflowsLive demo with Hex + MotherDuck on Nov 13

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>1.4.1.0</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 two main ways to programmatically authenticate with a valid MotherDuck token:

  1. Passing it in through the connection configuration
    Properties config = new Properties();
config.setProperty("motherduck_token", token);
Connection mdConn = DriverManager.getConnection("jdbc:duckdb:md:mdw", config);
  1. Passing the token as a connection string parameter:
Connection conn = DriverManager.getConnection("jdbc:duckdb:md:my_db?motherduck_token="+token);

See Authenticating to MotherDuck for more details.