民航电子数据库:select查询时部分字段缺失


前言

1、对接民航电子数据库

2、框架为shardingsphere + caedb + mybatis

3、部分SQL查询时,会出现字段缺失的情况

4、查看日志打印出来的SQL,字段并未缺失


异常

这里省略SQL语句

在这里插入图片描述


排查

1、通过截图可以看出,数据库返回的字段是完整的,并没有缺失

在这里插入图片描述


2、但是在映射结果的时候,字段缺失了

在这里插入图片描述


3、发现缺失的字段,在SQL解析时,连字段别名都是错误的

在这里插入图片描述


4、发现执行SQL时,是以SQL92的语法来执行的,并不是MySQL

在这里插入图片描述


5、shardingsphere是根据数据库链接来判断数据库类型,由于cae还未合并到开源社区,所以找不到对应的数据库类型

在这里插入图片描述


原因

民航电子数据库(CAEDB)还未合并到开源社区,shardingsphere还未兼容cae数据库,所以shardingsphere处理SQL时,是以SQL92的语法来解析SQL,导致部分SQL出现奇奇怪怪的异常情况


解决

排除shardingsphere-sql-parser-binder 、shardingsphere-common,使用民航电子数据库那边提供的Jar包

缺点:shardingsphere版本无法升级,如果升级需要找民航电子数据库开发人员提供对应版本的Jar包

<dependency>
	<groupId>org.apache.shardingsphere</groupId>
	<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
	<version>4.1.1</version>
	<exclusions>
        <!--民航电子数据库:排除shardingsphere以下两个依赖-->
        <exclusion>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>shardingsphere-sql-parser-binder</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>shardingsphere-common</artifactId>
        </exclusion>
	</exclusions>
</dependency>
<!--民航电子数据库:引入本地依赖-->
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-sql-parser-binder</artifactId>
    <version>4.1.1</version>
    <systemPath>${project.basedir}/lib/apache-shardingsphere-binder-4.1.1.jar</systemPath>
    <scope>system</scope>
</dependency>
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>apache-shardingsphere-common</artifactId>
    <version>4.1.1</version>
    <systemPath>${project.basedir}/lib/apache-shardingsphere-common-4.1.1.jar</systemPath>
    <scope>system</scope>
</dependency>

更换后SQL正常执行

在这里插入图片描述


在这里插入图片描述


使用systemPath标签引入本地Jar包后无法打包

http://t.csdnimg.cn/iw1yw

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值