您的位置:首页 > 博客中心 > 数据库 >

ClickHouse的JDBC连接

时间:2022-09-07 11:13

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、执行

技术图片

 

热门排行

今日推荐

热门手游