依赖配置pom.xml
<dependency>
<groupId>cc.blynk.clickhouse</groupId>
<artifactId>clickhouse4j</artifactId>
<version>1.4.4</version>
</dependency>
CK基本信息
String driver = "cc.blynk.clickhouse.ClickHouseDriver";
String ip = "xxx.xxx.xxx.xxx";
String port = "8123";
String db = "db";
String user = "user";
String pwd = "pwd";
创建ClickHouse连接
Class.forName(driver);
StringBuffer urlSb = new StringBuffer()
.append("jdbc:clickhouse://")
.append(ip).append(":").append(port).append("/").append(db)
.append("?characterEncoding=utf8&useSSL=false");
Connection connection = DriverManager.getConnection(urlSb.toString(), user, pwd);
基本查询
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("show tables");
if(resultSet != null) {
while(resultSet.next()) {
String tableName = resultSet.getString(1);
System.err.println(tableName);
}
}
关闭相关连接
if(resultSet != null && !resultSet.isClosed()) resultSet.close();
if(statement != null && !statement.isClosed()) statement.close();
if(connection != null && !connection.isClosed()) connection.close();