---
sidebar_position: 1
title: JDBC driver
description: Connect to MotherDuck from Java applications using the official DuckDB JDBC driver.
---

import CodeBlock from '@theme/CodeBlock';
import appVersions from '@site/src/appVersions.json';

The official [DuckDB JDBC driver](https://duckdb.org/docs/api/java.html) supports MotherDuck out of the box!

To connect, you need a dependency on the driver. For example, in your Maven pom.xml file:

<CodeBlock language="xml">
{`<dependency>
    <groupId>org.duckdb</groupId>
    <artifactId>duckdb_jdbc</artifactId>
    <version>${appVersions.duckdb_jdbc}</version>
</dependency>`}
</CodeBlock>

Your code can then create a `Connection` by using `jdbc:duckdb:md:databaseName` connection string format:

```xml
Connection conn = DriverManager.getConnection("jdbc:duckdb:md:my_db");
```

This `Connection` can then be [used directly](https://docs.oracle.com/en/java/javase/17/docs/api/java.sql/java/sql/Connection.html) 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

```java
    Properties config = new Properties();
    config.setProperty("motherduck_token", token);
    Connection mdConn = DriverManager.getConnection("jdbc:duckdb:md:mdw", config);
```

2) Passing the token as a connection string parameter:

```java
Connection conn = DriverManager.getConnection("jdbc:duckdb:md:my_db?motherduck_token="+token);
```

See [Authenticating to MotherDuck](/key-tasks/authenticating-and-connecting-to-motherduck/authenticating-to-motherduck/authenticating-to-motherduck.md) for more details.
