Integrate Springboot+MybatisPlus+Dameng database

1. Install Dameng database visualization software in Windows environment

There is no installation introduction here

 The installation steps are very simple, and the software provided is also very comprehensive, especially the database migration tool, which supports many mainstream large-scale databases on the market, such as: Oracle, SQLServer, MySQL, DB2, PostgreSQL, Informix, Kingbase, Sybase, etc., personally tested, Very easy to use and very efficient. But Dameng has strict requirements on the storage length, so the length of some mysql varchar should be paid attention to

insert image description here

2. SpringBoot + Mybatis-Plus configuration

If the SpringBoot project wants to integrate the Dameng database, the first driver must be indispensable, and the second is the configuration file.

It is recommended to use a newer version of SpringBoot (I am using 2.5.14) and Mybatis-Plus (I am using 3.3.1):

<!--mybatis-plus包-->
<dependency>
  <groupId>com.baomidou</groupId>
  <artifactId>mybatis-plus-boot-starter</artifactId>
  <version>3.3.1</version>
</dependency>

 <!-- SpringBoot的依赖配置-->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-dependencies</artifactId>
  <version>2.5.14</version>
  <type>pom</type>
  <scope>import</scope>
</dependency>

<!--达梦驱动-->
<dependency>
  <groupId>com.dm</groupId>
  <artifactId>DmJdbcDriver</artifactId>
  <version>1.8.0</version>
</dependency>

Notice:

It is not possible to import this jar package directly. I can import it by uploading the jar package to the Maven private server warehouse built by myself. For details on how to build it, please refer to this article I wrote: jar package encryption----xjar (pro- test Available)_Xiaobobo's blog-CSDN blog , the article describes how to import it into your own maven warehouse. The picture below shows the location of the driver jar package, which is in the directory where Dameng Windows environment visualization software is installed:

insert image description here

But it is possible that this kind of import pom will fail to connect to the Dameng database

 So later I switched to this one, and it was fine. It’s outrageous. The specific reason has not been checked, and it may be a version problem.

 2.2 yaml file configuration

spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: dm.jdbc.driver.DmDriver
    url: jdbc:dm://localhost:5236?schema=online_supervision
   #若?schema=online_supervision连接不上,则用/online_supervision
    #数据库的使用用户
    username: SYSDBA
    #实际使用数据库的密码
    password: SYSDBA



mybatis-plus:
  configuration:
    cache-enabled: false
    local-cache-scope: statement
  global-config:
    db-config:
      logic-delete-value: 1
      logic-not-delete-value: 0
      schema: dpmp   # 达梦需要加上这个,这是mybatis-plus的配置,如果不加,则查询不到该模式下的数据
  mapper-locations: classpath:mapper/dm/*.xml

 Pit 1: Connection exception

 Unlike other data connections, you cannot directly ip+port/library name, you need ip+port?schema=library name

Attach my database structure, Dameng can automatically convert the database name and table name to uppercase (note, when creating a Dameng database instance, whether the configuration is case-sensitive ):

 After this configuration, the project can basically run. Let me summarize some of the problems I encountered:

1. Set case sensitivity

If case sensitivity is set, then assuming that the library name and table name are in lowercase, for example: sys_user, then the sql of Dameng needs to be changed to

select "id","name" from "library name (Dameng called mode name)"."sys_user", assuming the library name (mode name) is: dpmp

Then sql should select "id","name" "from dpmp"."sys_user"

So the most troublesome thing is this, that is, some query insertion methods encapsulated by mybatis-plus will report errors when used, because the default generated sql does not support Dameng

for example

 Because the lowercase field names and table names returned by Dameng, all the lowercase ones must be added with double quotes "", so if you use them directly, you will get an error. You need to rewrite these methods and rewrite sql

【problem causes】

When the Dameng database is set to be case-sensitive, lowercase identifiers should be enclosed in double quotes, otherwise they will be converted to uppercase. When an error is reported, the overall status is: Dameng database is set to be case-sensitive, and the database tables and fields are all lowercase. From the error report, Dameng has converted the database table sys_user to uppercase SYS_USER when querying. Because there is no uppercase SYS_USER table in the database, the query fails.

【Solution】

1. Set the Dameng database to be case-insensitive ( currently I use this, just add a library name directly to the mysql sql, and the mysql project is perfectly migrated to Dameng )
2. Rewrite the SQL query statement and change the database table name to and column names are enclosed in double quotes
3. Change the database table and column names to uppercase

 

Question 2: An error is reported when the scheduled task starts


After starting the service, because the scheduled task (quartz framework) is configured, the scheduled task configuration file is read, and when the scheduled task is checked, an error is reported that the configuration table related to the scheduled task cannot be found. I use quartz.properties here

Note: Since Dameng can be set to be case-insensitive, you don’t need to care about case (note that it is set when initializing the library), but! ! ! Notice! ! ! Dameng access tables are all schema. Table name access, the schema name is the name of the mysql library.

So here needs to be modified:

prop.put("org.quartz.jobStore.tablePrefix", "online_supervision.QRTZ_");

2. If case sensitivity is not set (convenient, no need to rewrite a large number of mybatis-plus methods)

If the library name, table name, and field name are in lowercase (preferably all in uppercase), Dameng will automatically return to uppercase

So the entity class needs to be annotated

package com.supervision.core.workTickets.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

@TableName("ddpmp.sys_user")
public class SysUser {
    @TableId(value = "ID",type = IdType.ASSIGN_UUID)
    private String id;
    @TableField("NAME")
    private String name;
}

Guess you like

Origin blog.csdn.net/qq_38623939/article/details/130864204