---
title: "Integrating ClickHouse with Java"
description: "Modern v2 client built around RowBinary and Arrow streams. Reactive R2DBC support, async I/O, and full Cloud auth."
category: "LANGUAGE_CLIENT"
support: "CORE"
docs: "https://clickhouse.com/docs/integrations/language-clients/java"
---

# Java


#### Maven
```xml
    <dependency>
        <groupId>com.clickhouse</groupId>
        <artifactId>clickhouse-jdbc</artifactId>
        <version>0.3.2-patch11</version>
    </dependency>
```
#### Open a connection
```java
    Properties prop = new Properties();
    prop.setProperty("username", "default");
    prop.setProperty("password", "<password>");
    Connection conn = DriverManager.getConnection("jdbc:ch:https://<host>:8443?insert_quorum=auto", prop);
```
#### Create a table
```java
    Statement stmt = conn.createStatement();
    stmt.execute("CREATE TABLE IF NOT EXISTS jdbc_test(idx Int8, str String) ENGINE = MergeTree ORDER BY idx");
```

#### Write data to a table
```java
    try (PreparedStatement ps = conn.prepareStatement(
            "insert into jdbc_test select col1, col2 from input('col1 Int8, col2 String')")) {
        for (int i = 0; i < 10; i++) {
            ps.setInt(1, i);
            ps.setString(2, "test:" + i); // col1
            // parameters will be write into buffered stream immediately in binary format
            ps.addBatch(); 
        }
        // stream everything on-hand into ClickHouse
        ps.executeBatch(); 
    }
```

#### Read data from a table
```java
    ResultSet rs = stmt.executeQuery("select * from jdbc_test");
    while (rs.next()) {
        System.out.println(String.format("idx: %s str: %s", rs.getString(1), rs.getString(2)));
    }
```