clickhouse21.7.11.3 JAVA-JDBC查询

介绍

本文介绍 clickhouse 官方最新版 0.3.2-patch11 驱动

与老版驱动相比,maven 的 gav 有改动,驱动类有改动

使用的是 HTTP 端口 8123

也支持 MyBatis 连接操作

创建 maven 工程

pom.xml

添加下面依赖:

<dependency>
    <groupId>com.clickhouse</groupId>
    <artifactId>clickhouse-jdbc</artifactId>
    <version>0.3.2-patch11</version>
</dependency>

java 代码

package std;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;

public class Std1 {
    public static void main(String[] args) throws Exception {
        Class.forName("com.clickhouse.jdbc.ClickHouseDriver");
        Connection connection = DriverManager.getConnection("jdbc:clickhouse://hadoop3:8123");

        Statement statement = connection.createStatement();
        ResultSet rs = statement.executeQuery("select sid,name,age,height,create_time from t_student_mt");
        while (rs.next()){
            int sid = rs.getInt(1);
            String name = rs.getString(2);
            int age = rs.getInt(3);
            int height = rs.getInt(4);
            Date createTime = rs.getDate(5);
            System.out.println(sid+","+name+","+age+","+height+","+createTime);
        }
        rs.close();
        connection.close();

    }
}

原文出处:https://malaoshi.top/show_1IX4UJ6EYnwB.html