创建maven
在pom中加入clickhouse依赖
<!-- Clickhouse -->
<dependency>
<groupId>ru.yandex.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.3.1</version>
</dependency>
编写API
import java.sql.*;
public class ClickHouse_Select {
public static void main(String[] args) throws SQLException {
Connection connection = null;
PreparedStatement preparedStatement =null;
ResultSet resultSet =null;
try {
Class.forName("ru.yandex.clickhouse.ClickHouseDriver");
connection = DriverManager.getConnection("jdbc:clickhouse://spark01:8123");
preparedStatement = connection.prepareStatement("select * from test_binlog.user");
resultSet = preparedStatement.executeQuery();
System.out.println(resultSet);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
} finally {
connection.close();
preparedStatement.close();
resultSet.close();
}
}
}
删除,插入操作都类似只是修改prepareStatement()中的语句就行