D
D
DDwrt1002019-06-18 15:40:23
Java
DDwrt100, 2019-06-18 15:40:23

How to solve java.sql.SQLException: Read timed out problem?

Good afternoon.
There is a project on Spring with two databases.
The connection is defined by the following code

@Bean
    @Primary
    @ConfigurationProperties("spring.pg.datasource")
    public DataSourceProperties firstDataSourceProperties() {
        return new DataSourceProperties();
    }


    @Bean
    @ConfigurationProperties("spring.ch.datasource")
    public DataSourceProperties secondDataSourceProperties() {
        return new DataSourceProperties();
    }


    @Bean(name = "PG")
    @Primary
    @ConfigurationProperties("spring.pg.datasource.configuration")
    public DataSource firstDataSource() {
        return firstDataSourceProperties()
                .initializeDataSourceBuilder()
                .type(HikariDataSource.class)
                .build();
    }


    @Bean(name = "CH")
    @ConfigurationProperties("spring.ch.datasource.configuration")
    public DataSource secondDataSource() {
        return secondDataSourceProperties()
                .initializeDataSourceBuilder()
                .type(HikariDataSource.class)
                .build();
    }

When using HikariDataSource, the second database, when queried, returns:
java.sql.SQLException: Read timed out
  at com.github.housepower.jdbc.connect.PhysicalConnection.receiveResponse(PhysicalConnection.java:88) ~[clickhouse-native-jdbc-1.7-stable.jar:na]
  at com.github.housepower.jdbc.connect.PhysicalConnection.receiveHello(PhysicalConnection.java:72) ~[clickhouse-native-jdbc-1.7-stable.jar:na]
  at com.github.housepower.jdbc.ClickHouseConnection.serverInfo(ClickHouseConnection.java:180) ~[clickhouse-native-jdbc-1.7-stable.jar:na]
  at com.github.housepower.jdbc.ClickHouseConnection.createPhysicalInfo(ClickHouseConnection.java:164) ~[clickhouse-native-jdbc-1.7-stable.jar:na]

At the same time, if you change the DataSource class for the problematic database to BasicDataSource, the construction starts working.
How can this problem be solved? What can you see?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DDwrt100, 2019-06-18
@DDwrt100

Problem solved,
I should have added the following line

@Bean(name = "CH")
    @ConfigurationProperties("spring.ch.datasource.configuration")
    public DataSource secondDataSource() {
<b>      HikariConfig  hikari = new HikariConfig();
      hikari.setConnectionTestQuery("show tables");</b>
        return secondDataSourceProperties()
                .initializeDataSourceBuilder()
                .type(HikariDataSource.class)
                .build();
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question