Skip to main content

JDBC driver

Java Database Connectivity (JDBC) driver for connecting Java applications to MotherDuck. 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.5.5.1</version>
</dependency>

If you need the standalone JAR, download the latest MotherDuck-supported DuckDB JDBC driver.

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.