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(); } }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot