java.lang.RuntimeException: ru.yandex.clickhouse.except.ClickHouseUnknownException: ClickHouse exception, code: 1002, host: 10.3.1.59, port: 9000; Port 9000 is for clickhouse-client program.
You must use port 8123 for HTTP.
at ru.yandex.clickhouse.ClickHouseConnectionImpl.initTimeZone(ClickHouseConnectionImpl.java:99)
at ru.yandex.clickhouse.ClickHouseConnectionImpl.<init>(ClickHouseConnectionImpl.java:80)
at ru.yandex.clickhouse.ClickHouseDriver.connect(ClickHouseDriver.java:55)
at ru.yandex.clickhouse.ClickHouseDriver.connect(ClickHouseDriver.java:47)
at ru.yandex.clickhouse.ClickHouseDriver.connect(ClickHouseDriver.java:29)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at com.crgt.gtdata.ClickHouseTest2.main(ClickHouseTest2.java:24)
Caused by: ru.yandex.clickhouse.except.ClickHouseUnknownException: ClickHouse exception, code: 1002, host: 10.3.1.59, port: 9000; Port 9000 is for clickhouse-client program.
You must use port 8123 for HTTP.
at ru.yandex.clickhouse.except.ClickHouseExceptionSpecifier.getException(ClickHouseExceptionSpecifier.java:91)
at ru.yandex.clickhouse.except.ClickHouseExceptionSpecifier.specify(ClickHouseExceptionSpecifier.java:55)
at ru.yandex.clickhouse.except.ClickHouseExceptionSpecifier.specify(ClickHouseExceptionSpecifier.java:28)
at ru.yandex.clickhouse.ClickHouseStatementImpl.checkForErrorAndThrow(ClickHouseStatementImpl.java:875)
at ru.yandex.clickhouse.ClickHouseStatementImpl.getInputStream(ClickHouseStatementImpl.java:616)
at ru.yandex.clickhouse.ClickHouseStatementImpl.executeQuery(ClickHouseStatementImpl.java:117)
at ru.yandex.clickhouse.ClickHouseStatementImpl.executeQuery(ClickHouseStatementImpl.java:100)
at ru.yandex.clickhouse.ClickHouseStatementImpl.executeQuery(ClickHouseStatementImpl.java:95)
at ru.yandex.clickhouse.ClickHouseStatementImpl.executeQuery(ClickHouseStatementImpl.java:90)
at ru.yandex.clickhouse.ClickHouseConnectionImpl.initTimeZone(ClickHouseConnectionImpl.java:94)
... 7 more
Caused by: java.lang.Throwable: Port 9000 is for clickhouse-client program.
You must use port 8123 for HTTP.
at ru.yandex.clickhouse.except.ClickHouseExceptionSpecifier.specify(ClickHouseExceptionSpecifier.java:53)
... 15 more
2 ,后来测试发现,同时引入了两个jar包,一个官方jar包,一个非官方jar包
<dependency>
<groupId>com.github.housepower</groupId>
<artifactId>clickhouse-native-jdbc</artifactId>
<version>1.7-stable</version>
</dependency>
<dependency>
<groupId>ru.yandex.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.2</version>
</dependency>
3,官方jar包默认是8123端口,而第三方jar包(clickhouse-native-jdbc)默认端口是9000,如果同时引入两个jar包,虽然自己指定
Class.forName("com.github.housepower.jdbc.ClickHouseDriver")为第三方jar包,实际执行中,使用官方端口.
4,查看了源代码
4.1官方第三方jar包是继承了
4.2 官方jar包是 直接继承 Driver类
4, 解决方案,只引入一个jar包,如果是官方的jar包就使用8123端口,如果是第三方是 9000端口
5.最后附上测试代码
public class ClickHouseTest3 {
public static void main(String[] args) {
System.out.println("test click house");
try {
Class.forName("com.github.housepower.jdbc.ClickHouseDriver");//第三方jar包
// Class.forName("ru.yandex.clickhouse.ClickHouseDriver");//官方
//如果官方jar包引入,则下面不能执行,如果包官方jar包去掉,则可以执行
Connection connection = DriverManager.getConnection("jdbc:clickhouse://127.0.0.1:9000");//第三方
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("select count(*) from test");
if (rs.next()) {
int count = rs.getInt(1);
System.out.println(count);
}
}catch (Exception e){
e.printStackTrace();
}
}
}
转载:https://blog.csdn.net/wppwpp1/article/details/102574955
查看评论