Commissioning the Spring Boot Sample Program
In the Local Windows Environment
In the clickhouse-rest-client-example sample code, only JDK 8 and JDK 17 are supported.
Compiling and running the program
You can run the application in the Windows environment after you finish writing application code. If the local and cluster service planes can communicate with each other, you can perform the commissioning on the local host. Right-click ClickHouseApplication in IntelliJ IDEA project clickhouse-rest-client-examples in the development environment, and then choose Run ClickHouseApplication from the shortcut menu to run the application project.

Procedure
- Copy the clickhouse-example.properties path on the IDEA page. Right-click clickhouse-example.properties and choose Copy Path/Reference > Absolute Path from the shortcut menu. Figure 1 Copying absolute path of the configuration file
- In ClickHouseFunc.java, replace the path of proPath in the getProperties() method with clickhouse-example.properties. Figure 2 Replacing the path
Viewing the Commissioning Result
- After the ClickHouse Spring Boot service is started, the ClickHouse sample interface is used to trigger the running of the sample code. Enter the link of the specific operation to be performed in the address box of the browser, for example, http://localhost:8080/clickhouse/executeQuery. The following result is returned:
ClickHouse springboot client runs normally.
- View the clickhouse-springboot-example.log file to obtain the application running status.
After the clickhouse-springboot sample is run, the following information is displayed on the console:
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.7.0) 2023-02-06 17:58:22.144 INFO 20556 --- [ main] c.h.f.c.e.s.r.ClickHouseApplication : Starting ClickHouseApplication using Java 1.8.0_181 on DESKTOP-64PQBSD with PID 20556 (D:\Code\cloudBU\sample_project\src\springboot\clickhouse-examples\clickhouse-rest-client-example\target\classes started by l00467039 in D:\Code\cloudBU\sample_project\src\springboot\clickhouse-examples\clickhouse-rest-client-example) 2023-02-06 17:58:22.146 INFO 20556 --- [ main] c.h.f.c.e.s.r.ClickHouseApplication : No active profile set, falling back to 1 default profile: "default" 2023-02-06 17:58:22.815 INFO 20556 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2023-02-06 17:58:22.820 INFO 20556 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2023-02-06 17:58:22.821 INFO 20556 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.63] 2023-02-06 17:58:22.928 INFO 20556 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2023-02-06 17:58:22.928 INFO 20556 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 750 ms 2023-02-06 17:58:23.175 INFO 20556 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2023-02-06 17:58:23.181 INFO 20556 --- [ main] c.h.f.c.e.s.r.ClickHouseApplication : Started ClickHouseApplication in 1.388 seconds (JVM running for 3.989) 2023-02-06 17:58:32.640 INFO 20556 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2023-02-06 17:58:32.640 INFO 20556 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2023-02-06 17:58:32.641 INFO 20556 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms 2023-02-06 17:58:32.656 INFO 20556 --- [nio-8080-exec-1] .f.c.e.s.r.c.ClickHouseExampleController : Begin to execute query in clickhouse... 2023-02-06 17:58:32.658 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : loadBalancerIPList is 192.168.6.24, loadBalancerHttpPort is 21422, user is ckuser, clusterName is default_cluster, isSec is true. 2023-02-06 17:58:32.659 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : ckLbServerList current member is 0, ClickhouseBalancer is 192.168.6.24:21422 2023-02-06 17:58:32.664 INFO 20556 --- [nio-8080-exec-1] ru.yandex.clickhouse.ClickHouseDriver : Driver registered 2023-02-06 17:58:32.665 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Try times is 0, current load balancer is 192.168.6.24:21422. 2023-02-06 17:58:35.494 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Execute sql drop table if exists testdb.testtb on cluster default_cluster no delay, time is 216 ms 2023-02-06 17:58:35.495 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Try times is 0, current load balancer is 192.168.6.24:21422. 2023-02-06 17:58:36.074 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Execute sql drop table if exists testdb.testtb_all on cluster default_cluster no delay, time is 196 ms 2023-02-06 17:58:36.074 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Try times is 0, current load balancer is 192.168.6.24:21422. 2023-02-06 17:58:36.765 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Execute sql create database if not exists testdb on cluster default_cluster, time is 218 ms 2023-02-06 17:58:36.765 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Try times is 0, current load balancer is 192.168.6.24:21422. 2023-02-06 17:58:37.364 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Execute sql create table testdb.testtb on cluster default_cluster (name String, age UInt8, date Date)engine=ReplicatedMergeTree('/clickhouse/tables/{shard}/testdb.testtb','{replica}') partition by toYYYYMM(date) order by age, time is 198 ms 2023-02-06 17:58:37.366 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Try times is 0, current load balancer is 192.168.6.24:21422. 2023-02-06 17:58:37.872 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Execute sql create table testdb.testtb_all on cluster default_cluster as testdb.testtb ENGINE = Distributed(default_cluster,testdb,testtb, rand());, time is 160 ms 2023-02-06 17:58:38.959 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Insert batch time is 591 ms 2023-02-06 17:58:41.114 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Insert batch time is 572 ms 2023-02-06 17:58:43.095 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Insert batch time is 413 ms 2023-02-06 17:58:45.220 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Insert batch time is 543 ms 2023-02-06 17:58:47.207 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Insert batch time is 406 ms 2023-02-06 17:58:49.236 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Insert batch time is 460 ms 2023-02-06 17:58:51.197 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Insert batch time is 390 ms 2023-02-06 17:58:53.233 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Insert batch time is 466 ms 2023-02-06 17:58:55.355 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Insert batch time is 555 ms 2023-02-06 17:58:57.321 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Insert batch time is 386 ms 2023-02-06 17:58:58.832 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Inert all batch time is 20564 ms 2023-02-06 17:58:58.832 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Try times is 0, current load balancer is 192.168.6.24:21422. 2023-02-06 17:58:59.256 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Execute sql select * from testdb.testtb_all order by age limit 10, time is 119 ms 2023-02-06 17:58:59.257 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Try times is 0, current load balancer is 192.168.6.24:21422. 2023-02-06 17:58:59.972 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.restclient.impl.Util : Execute sql select toYYYYMM(date),count(1) from testdb.testtb_all group by toYYYYMM(date) order by count(1) DESC limit 10, time is 289 ms 2023-02-06 17:58:59.973 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : huawei_234 0 2022-12-16 2023-02-06 17:58:59.973 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : huawei_1805 0 2022-12-21 2023-02-06 17:58:59.973 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : huawei_3359 0 2022-12-13 2023-02-06 17:58:59.973 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : huawei_4275 0 2022-12-09 2023-02-06 17:58:59.973 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : huawei_4307 0 2022-12-20 2023-02-06 17:58:59.973 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : huawei_4586 0 2022-12-02 2023-02-06 17:58:59.973 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : huawei_6326 0 2022-12-18 2023-02-06 17:58:59.973 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : huawei_9878 0 2022-12-06 2023-02-06 17:58:59.974 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : huawei_2482 0 2022-12-18 2023-02-06 17:58:59.974 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : huawei_2904 0 2022-12-25 2023-02-06 17:58:59.974 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : 202201 8628 2023-02-06 17:58:59.974 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : 202208 8587 2023-02-06 17:58:59.974 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : 202205 8558 2023-02-06 17:58:59.974 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : 202210 8547 2023-02-06 17:58:59.974 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : 202207 8463 2023-02-06 17:58:59.974 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : 202203 8379 2023-02-06 17:58:59.974 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : 202204 8351 2023-02-06 17:58:59.974 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : 202206 8300 2023-02-06 17:58:59.974 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : 202209 8297 2023-02-06 17:58:59.974 INFO 20556 --- [nio-8080-exec-1] c.h.f.c.e.s.r.impl.ClickHouseFunc : 202212 8228
In a Linux Environment
The ClickHouse Spring Boot applications can run in a Linux environment. After you finish writing the application code, you can upload the JAR file to the prepared Linux environment.
Prerequisites
JDK has been installed on Linux. The version must be the same as JDK version of the JAR file exported from IntelliJ IDEA. Java environment variables have been set.
Compiling and running the program
- Click Maven on the right of IDEA, expand Lifecycle, and double-click package to package the current project.

- Log in to the ClickHouse client node as user root, create a running directory, for example, /opt/test, and obtain the JAR package whose name contains -with-dependencies from the target directory of IDEA. Upload the JAR package and the conf folder in the IDEA to the /opt/test directory, as shown in the following figure.

- Run the following commands to set environment variables and run the JAR package:
cd Client installation path
source bigdata_env
cd /opt/test
java -jar clickhouse-examples-1.0-SNAPSHOT-jar-with-dependencies.jar
The command output is displayed as follows:

- Call the Spring Boot sample API of ClickHouse to trigger running the sample code.
- For the Windows environment:
Open the browser, enter http://IP address of the ClickHouse client node:8080/clickhouse/executeQuery in the address box, and check the returned information.
ClickHouse springboot client runs normally.
- For the Linux environment:
Log in to the ClickHouse client node and run the following command to view shell logs and log files in Linux:
curl http://localhost:8080/clickhouse/executeQuery
vi clickhouse-springboot-example.log

- For the Windows environment:
What is your overall rating for this page?
Thank 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