Skip to main content


The Kùzu Java API is packaged and distributed as a jar file. You can manually download the latest version here. The detailed docs for Java API can be found here. After the jar file is downloaded and placed into the project directory, it can be referenced in classpath manually with the -cp option.

  • Setup: In this example, we assume the jar file and the Java code reside in the following directory structure:
|-- dataset
| |-- user.csv
| |-- city.csv
| |-- follows.csv
| |-- lives-in.csv
|-- src/main
| |-- java/org/example/
| |-- resources/kuzu_java.jar
  • Below is a Main example class demonstrating typical usage:
package org.example;
import com.kuzudb.*;

public class Main {

public static void main(String[] args) throws KuzuObjectRefDestroyedException {
String db_path = "./testdb";
KuzuDatabase db = new KuzuDatabase(db_path, 0);
KuzuConnection conn = new KuzuConnection(db);

// Create tables.
conn.query("CREATE NODE TABLE User(name STRING, age INT64, PRIMARY KEY (name))");
conn.query("CREATE NODE TABLE City(name STRING, population INT64, PRIMARY KEY (name))");
conn.query("CREATE REL TABLE Follows(FROM User TO User, since INT64)");
conn.query("CREATE REL TABLE LivesIn(FROM User TO City)");

// Load data.
KuzuQueryResult r1 = conn.query("COPY User FROM './dataset/user.csv'");

KuzuQueryResult r2 = conn.query("COPY City FROM './dataset/city.csv'");

KuzuQueryResult r3 = conn.query("COPY Follows FROM './dataset/follows.csv'");

KuzuQueryResult r4 = conn.query("COPY LivesIn FROM './dataset/lives-in.csv'");

// Execute a simple query.
KuzuQueryResult result =
conn.query("MATCH (a:User)-[f:Follows]->(b:User) RETURN, f.since,;");
System.out.println("Num tuples: " + result.getNumTuples());

while (result.hasNext()) {
KuzuFlatTuple row = result.getNext();
System.out.println("Row: " + row);
  • To execute the example, navigate to the project root directory and run the following command:
java -cp '.:src/main/resources/kuzu_java.jar' src/main/java/org/example/
  • For users who prefer Maven, our jar file can also be manually referenced from your Maven configuration:

Please note that we will soon provide a more convenient Maven-based solution for installing our API directly from Maven Central.