当前位置:Gxlcms > 数据库问题 > ClickHouse的JDBC连接

ClickHouse的JDBC连接

时间:2021-07-01 10:21:17 帮助过:21人阅读

1、增加依赖

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

  

 

2、代码实现

public class ClickHouseJdbc {
    public static void main(String[] args) throws Exception {
        // 注册驱动
        Class.forName("ru.yandex.clickhouse.ClickHouseDriver");
        Connection conn = DriverManager.getConnection("jdbc:clickhouse://118.xx.xx.101:8123/db_test");
        PreparedStatement ps = conn.prepareStatement("select * from dis_all ");
        ResultSet set = ps.executeQuery();
        while (set.next()){
            String id = set.getString("id");
            String date = set.getString("date");
            System.out.println(id + "----" + date);
        }
        set.close();
        ps.close();
        conn.close();
        
    }
}

  

3、执行

技术图片

 

ClickHouse的JDBC连接

标签:ima   nec   manage   while   manager   use   click   img   end   

人气教程排行