Help Center> GaussDB(for MySQL)> User Guide> HTAP Analysis> Connecting to an HTAP Instance> Connecting to an HTAP Instance Through HTTPS
Updated on 2024-03-01 GMT+08:00

Connecting to an HTAP Instance Through HTTPS

Prerequisites

  • You are familiar with:
    • Computer basics
    • Java
    • JDBC knowledge
  • You have downloaded official ClickHouse JDBC driver.
  • SSL is enabled for an HTAP instance and SSL CA certificate has been downloaded. For details, see Enabling SSL.

Precautions

Connecting to an HTAP instance through HTTPS increases the network connection response time and CPU usage. You are advised tp use HTTPS only when the external network is used and encryption is required.

Sample Code

The following is an example of the Java code you could use for connecting to an HTAP instance. For details about other languages, see ClickHouse official document.

import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.ResultSet; 
import java.sql.Statement; 
import java.sql.SQLException; 
public void run() throws InterruptedException {
    final ClickHouseProperties clickHouseProperties = new ClickHouseProperties();
    clickHouseProperties.setSslRootCertificate("/user/CA.pem");
    clickHouseProperties.setSsl(true);
    clickHouseProperties.setSslMode("none");
    clickHouseProperties.setUser("test");
    clickHouseProperties.setPassword("123456Aa");
    clickHouseProperties.setSocketTimeout(2 * 3600 * 1000);
    final BalancedClickhouseDataSource dataSource = new BalancedClickhouseDataSource ("jdbc:<External network address, read/write internal network address>:<HTTPS port number>/<Database name>?ssl=true", clickHouseProperties);
    try {
        final ClickHouseConnection conn = dataSource.getConnection();
        conn.createStatement().executeQuery("select now()");
    } catch (Throwable e) {
        e.printStackTrace();
    }
}