国产数据库人大金仓适配
kingbase8 人大金仓
·
1、Application.java
@Configuration
public class DataSourceConfig {
@Bean
public DatabaseIdProvider getDatabaseIdProvider() {
DatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider();
Properties p = new Properties();
p.setProperty("MySQL", "mysql");
p.setProperty("Kingbase", "kingbase8");
databaseIdProvider.setProperties(p);
return databaseIdProvider;
}
}
2、通过yml文件引入datasource(人大金仓)
spring:
datasource:
url: jdbc:kingbase8://10.0.10.73:54321/xxx...
username: xxx
password: xxx
driver-class-name: com.kingbase8.Driver
3、添加databaseId=“kingbase8”/"oracle"即可完成
在mapper中进行sql厂商标识的注入
<!--第一种:复制两个片段直接加上databaseId="kingbase8"/"oracle"-->
<select id="selectAllCoco" resultType="com.note.note.pojo.Coco" databaseId="kingbase8">
select id,name from cocodb;
</select>
<select id="selectAllCoco" resultType="com.note.note.pojo.Coco" databaseId="oracle">
select id,name from cocodb;
</select>
<!--第二种:引入if test = "kingbase8"/"oracle" databaseId="kingbase8"/"oracle" 进行改写-->
<insert id="insert">
<selectKey keyProperty="id" resultType="int" order="BEFORE">
<if test="_databaseId == 'oracle'">
select seq_users.nextval from dual
</if>
<if test="_databaseId == 'db2'">
select nextval for seq_users from sysibm.sysdummy1"
</if>
</selectKey>
insert into users values (#{id}, #{name})
</insert>
更多推荐
已为社区贡献2条内容
所有评论(0)