Skip to content

Commit e1bd49f

Browse files
committed
clickhouse
1 parent 26e377e commit e1bd49f

File tree

7 files changed

+107
-17
lines changed

7 files changed

+107
-17
lines changed

Demo/pom.xml

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,39 @@
2626
<artifactId>apijson-framework</artifactId>
2727
<version>4.7.0</version>
2828
</dependency>
29-
3029
<!-- 需要用的数据库 JDBC 驱动 -->
31-
<dependency>
32-
<groupId>mysql</groupId>
33-
<artifactId>mysql-connector-java</artifactId>
34-
<version>8.0.22</version>
35-
</dependency>
36-
<dependency>
37-
<groupId>org.postgresql</groupId>
38-
<artifactId>postgresql</artifactId>
39-
<version>42.2.18</version>
40-
</dependency>
30+
<!-- <dependency>-->
31+
<!-- <groupId>mysql</groupId>-->
32+
<!-- <artifactId>mysql-connector-java</artifactId>-->
33+
<!-- <version>8.0.22</version>-->
34+
<!-- </dependency>-->
35+
<!-- <dependency>-->
36+
<!-- <groupId>org.postgresql</groupId>-->
37+
<!-- <artifactId>postgresql</artifactId>-->
38+
<!-- <version>42.2.18</version>-->
39+
<!-- </dependency>-->
4140
<!-- Oracle, SQLServer 等其它数据库的 JDBC 驱动,可以在这里加上 Maven 依赖或 libs 目录放 Jar 包并依赖 -->
41+
<!-- <dependency>-->
42+
<!-- <groupId>cc.blynk.clickhouse</groupId>-->
43+
<!-- <artifactId>clickhouse4j</artifactId>-->
44+
<!-- <version>1.4.4</version>-->
45+
<!-- </dependency>-->
46+
<dependency>
47+
<groupId>ru.yandex.clickhouse</groupId>
48+
<artifactId>clickhouse-jdbc</artifactId>
49+
<version>0.3.1</version>
50+
<exclusions>
51+
<exclusion>
52+
<groupId>com.fasterxml.jackson.core</groupId>
53+
<artifactId>jackson-core</artifactId>
54+
</exclusion>
55+
<exclusion>
56+
<groupId>com.fasterxml.jackson.core</groupId>
57+
<artifactId>jackson-databind</artifactId>
58+
</exclusion>
4259

60+
</exclusions>
61+
</dependency>
4362
<!-- 需要用的 SpringBoot 框架,1.4.0 以上 -->
4463
<dependency>
4564
<groupId>org.springframework.boot</groupId>

Demo/src/main/java/apijson/demo/DemoApplication.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package apijson.demo;
1616

17+
import apijson.Log;
1718
import org.springframework.boot.SpringApplication;
1819
import org.springframework.boot.autoconfigure.SpringBootApplication;
1920
import org.springframework.context.annotation.Bean;
@@ -25,6 +26,8 @@
2526
import apijson.framework.APIJSONCreator;
2627
import apijson.orm.SQLConfig;
2728

29+
import static apijson.framework.APIJSONSQLConfig.TAG;
30+
2831

2932
/**SpringBootApplication
3033
* 右键这个类 > Run As > Java Application
@@ -41,7 +44,15 @@ public SQLConfig createSQLConfig() {
4144
return new DemoSQLConfig();
4245
}
4346
};
44-
47+
try { //加载驱动程序
48+
Log.d(TAG, "尝试加载 clickhouse 驱动 <<<<<<<<<<<<<<<<<<<<< ");
49+
Class.forName("ru.yandex.clickhouse.ClickHouseDriver");
50+
Log.d(TAG, "成功加载 clickhouse 驱动!>>>>>>>>>>>>>>>>>>>>> ");
51+
}
52+
catch (ClassNotFoundException e) {
53+
e.printStackTrace();
54+
Log.e(TAG, "加载 clickhouse 驱动失败,请检查 pom.xml 中 ru.yandex.clickhouse 版本是否存在以及可用 !!!");
55+
}
4556

4657
// 把以下需要用到的数据库驱动取消注释即可,如果这里没有可以自己新增
4758
// try { //加载驱动程序
@@ -64,6 +75,7 @@ public SQLConfig createSQLConfig() {
6475
// Log.e(TAG, "加载 Oracle 驱动失败,请检查 pom.xml 中 com.oracle.jdbc 版本是否存在以及可用 !!!");
6576
// }
6677

78+
6779
}
6880

6981
public static void main(String[] args) throws Exception {

Demo/src/main/java/apijson/demo/DemoSQLConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class DemoSQLConfig extends APIJSONSQLConfig {
2727

2828
static {
2929
DEFAULT_DATABASE = DATABASE_MYSQL; // TODO 默认数据库类型,改成你自己的
30-
DEFAULT_SCHEMA = "sys"; // TODO 默认模式名,改成你自己的,默认情况是 MySQL: sys, PostgreSQL: public, SQL Server: dbo, Oracle:
30+
DEFAULT_SCHEMA = "test"; // TODO 默认模式名,改成你自己的,默认情况是 MySQL: sys, PostgreSQL: public, SQL Server: dbo, Oracle:
3131

3232
// 表名和数据库不一致的,需要配置映射关系。只使用 APIJSONORM 时才需要;
3333
// 如果用了 apijson-framework 且调用了 APIJSONApplication.init
@@ -42,19 +42,19 @@ public class DemoSQLConfig extends APIJSONSQLConfig {
4242

4343
@Override
4444
public String getDBVersion() {
45-
return "5.7.21"; // "8.0.11"; // TODO 改成你自己的 MySQL 或 PostgreSQL 数据库版本号 // MYSQL 8 和 7 使用的 JDBC 配置不一样
45+
return "21.7.5.29"; // "8.0.11"; // TODO 改成你自己的 MySQL 或 PostgreSQL 数据库版本号 // MYSQL 8 和 7 使用的 JDBC 配置不一样
4646
}
4747

4848
@JSONField(serialize = false) // 不在日志打印 账号/密码 等敏感信息
4949
@Override
5050
public String getDBUri() {
51-
return "jdbc:mysql://localhost:3306"; // TODO 改成你自己的,TiDB 可以当成 MySQL 使用,默认端口为 4000
51+
return "jdbc:clickhouse://192.168.108.128:8123"; // TODO 改成你自己的,TiDB 可以当成 MySQL 使用,默认端口为 4000
5252
}
5353

5454
@JSONField(serialize = false) // 不在日志打印 账号/密码 等敏感信息
5555
@Override
5656
public String getDBAccount() {
57-
return "root"; // TODO 改成你自己的
57+
return "default"; // TODO 改成你自己的
5858
}
5959

6060
@JSONField(serialize = false) // 不在日志打印 账号/密码 等敏感信息

README.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,60 @@
1-
Demo
1+
进行测试的Demo项目
2+
3+
📝 内容:SpringBoot+APIJSON 接入 clickhouse数据库
4+
5+
📙 clickhouse官方文档:[点击](https://clickhouse.tech/docs/zh/sql-reference/syntax/)
6+
7+
8+
9+
**已经完成内容:**
10+
11+
👌 在虚拟机中安装了clickhouse,使用xshell连接,并把本地mysql中的测试数据全部迁移到了clickhouse中
12+
13+
![](images/1.png)
14+
15+
👌 使用DBeaver 连接了ClickHouse ,能方便查看数据
16+
17+
![](images/2.png)
18+
19+
20+
21+
👌 根据官方demo编写了clickhouse的demo,在本地运行项目能够在http://apijson.cn/api/ 进行基本的查询。
22+
23+
24+
25+
👌 APIPJSON-ORM 查询源码过了一遍
26+
27+
28+
29+
30+
31+
**待完成内容:**
32+
33+
测试
34+
35+
36+
37+
**遇见的bug:**
38+
39+
1. 解决了click-jdbc jar包版本直接引入与springboot-web包冲突的问题
40+
41+
2. 解决了远程数据库访问权限的问题
42+
43+
3. 解决了linux中 clickhouse数据库表名大小写识别的问题
44+
45+
4.
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+

image-20210801143124067.png

25.2 KB
Loading

images/1.png

24.9 KB
Loading

images/2.png

131 KB
Loading

0 commit comments

Comments
 (0)