Connecting to Crate with JDBC

Compatibility

Each major version of the Crate JDBC driver is bound to a major version of Crate. Find out which drivers are compatible to your Crate version with this compatibility list.

Add Crate to your Project

A simple way to configure your project to connect to a Crate cluster is to visit the JDBC driver page on Bintray and click the Set Me Up button. This will give you a Maven or Gradle configuration that can be pasted into your current project or downloaded for a new project.

For manual configuration follow these steps depending on your build system of choice.

Maven

Add the following to your pom.xml file:

...
<repositories>
    ...
    <repository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>central</id>
        <name>bintray</name>
        <url>http://dl.bintray.com/crate/crate</url>
    </repository>
</repositories>
...
<dependencies>
    ...
    <dependency>
        <groupId>io.crate</groupId>
        <artifactId>crate-jdbc</artifactId>
        <version>VERSION</version>
    </dependency>
</dependencies>
...

Gradle

Add Crate as a dependency to your Gradle file:

   repositories {
        ...
        jcenter()
    }

    dependencies {
        compile 'io.crate:crate-jdbc:VERSION'
        ...
    }

Connect to Crate

The Crate JDBC driver class is io.crate.client.jdbc.CrateDriver.

Connect to Crate Cluster with the Java DriverManager:

Class.forName("io.crate.client.jdbc.CrateDriver");
Connection conn = DriverManager.getConnection("crate://SERVER_IP:4300");

Want to Know More?

Next Steps