clickhousePort 9000 is for clickhouse-client program

Posted 九师兄

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了clickhousePort 9000 is for clickhouse-client program相关的知识,希望对你有一定的参考价值。


1.概述

转载:CLickHouse出现端口异常问题

执行一段代码,然后报错如下Port 9000 is for clickhouse-client program

详细的报错如下

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

详细的代码如下

 public void nativeClient3() throws Exception 
        Class.forName("com.github.housepower.jdbc.ClickHouseDriver");
        Connection connection = DriverManager.getConnection("jdbc:clickhouse://localhost:9000");

        PreparedStatement pstmt = connection.prepareStatement("insert into lcc.t_city values(?, ?, ?,?)");

        // insert 10 records
        for (int i = 0; i < 10; i++) 
            pstmt.setString(1, "panda_" + (i + 1));
            pstmt.setString(2, "panda_" + (i + 1));
            pstmt.setDate(2, new Date(System.currentTimeMillis()));
            pstmt.setInt(3, 18);
            pstmt.addBatch();
        
        pstmt.executeBatch();
    

后来测试发现,同时引入了两个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>

官方jar包默认是8123端口,而第三方jar包(clickhouse-native-jdbc)默认端口是9000,如果同时引入两个jar包,虽然自己指定

Class.forName("com.github.housepower.jdbc.ClickHouseDriver")

为第三方jar包,实际执行中,使用官方端口.

2.源代码

2.1 官方

官方第三方jar包是继承了

public class ClickHouseDriver implements Driver 

2.2 非官方

官方jar包是 直接继承 Driver类


public class ClickHouseDriver implements Driver 

    static 
        try 
            DriverManager.registerDriver(new ClickHouseDriver());
         catch (SQLException e) 
            throw new RuntimeException(e);
        
    

3.解决方案

解决方案,只引入一个jar包,如果是官方的jar包就使用8123端口,如果是第三方是 9000端口

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();
        
    
 

以上是关于clickhousePort 9000 is for clickhouse-client program的主要内容,如果未能解决你的问题,请参考以下文章

Bulid过程中中遇到的问题UnityEditor.BuildPlayerWindow+BuildMethodException: '' is an incorrect path fo

a start job is running fo ubuntu怎么解决

成功解决 运行报错信息:Error running xxx项目: Command line is too long. Shorten command line for xxx项目 or also fo

iOS开发-canOpenURL: failed for URL: "xx" - error:"This app is not allowed to query fo(代

Maven修改test/rsource的output folder报错Test source folder 'src/test/java'... is not also used fo

Docker 之WARNING: IPv4 forwarding is disabled. Networking will not work. 解决办法