天天看点

java通过jdbc连接clickhouse

先确认我们的ck服务正常,随便做个查询

java通过jdbc连接clickhouse
来到java项目,先引包

<dependency>
   <groupId>ru.yandex.clickhouse</groupId>
   <artifactId>clickhouse-jdbc</artifactId>
   <version>0.2.4</version>
</dependency>      

jdbc测试

public void clickHouseTest() throws ClassNotFoundException, SQLException {
        Class.forName("ru.yandex.clickhouse.ClickHouseDriver");
        Connection connection = DriverManager.getConnection("jdbc:clickhouse://*.*.*.*:8123/tutorial", "用户名", "密码");
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("select count(1) from tutorial.hits_v1");
        while (resultSet.next()) {
            System.out.println("查询结果为:" + resultSet.getString(1));
        }
    }      

结果

java通过jdbc连接clickhouse