最近项目涉及国产芯片、国产操作系统、国产数据库,总之全套国产化,选型用统信产品序列。就涉及开发框架适配国产数据库的问题:

1、spring boot2框架适配国产达梦8数据库或者瀚高数据库

pom.xml引入dm8的依赖:

 com.damengDmJdbcDriver188.1.2.141

com.highgoHgdbJdbc6.2.4

2、application-dev.yml配置druid数据源

# 数据源spring:datasource:type: com.alibaba.druid.pool.DruidDataSourcedruid:#driver-class-name: com.mysql.cj.jdbc.Driver#username: ${MYSQL_USER:root}#password: ${MYSQL_PWD:root}#url: jdbc:mysql://${MYSQL_HOST:pigx-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:pigx_json_flow}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true#validation-query: SELECT 1#driver-class-name: dm.jdbc.driver.DmDriver#username: SYSDBA#password: C##qlywadmin2023#url: jdbc:dm://127.0.0.1:5236?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8driver-class-name: com.highgo.jdbc.Driverusername: highgopassword: Password@123url: jdbc:highgo://localhost:5866/highgovalidation-query: SELECT 1time-between-eviction-runs-millis: 18800stat-view-servlet:enabled: trueallow: ""url-pattern: /druid/*filter:stat:enabled: truelog-slow-sql: trueslow-sql-millis: 10000merge-sql: falsetest-while-idle: true#wall:#config:#multi-statement-allow: true

3、mybatis适配

需要注意的是mysql数据库里的name、level、type等关键字在mapper.xml里是带单引号的,到达梦8或者瀚高数据库里时要去掉。另外瀚高数据库的模糊查询需要用::text指明字段类型,否则会报错;按id查询返回一条记录时要用resultType 指明实体类型,否则回报返回多条错误。

select from COMPANY_FRAME.sys_deptwhere id = #{id,jdbcType=VARCHAR}
UPDATE COMPANY_FRAME.sys_deptset relation_code=replace(relation_code,#{oldStr}::text,#{newStr}::text)where relation_code LIKE CONCAT(#{relationCode}::text,'%')

注意了以上3点,基本就避坑了,好了,更新完毕,欢迎一键三连,关注我的微信号 获取更多资讯~