1.配置数据源
url配置
jdbc:dm://127.0.0.1:5236/test?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8
2.maven配置 很重要 很重要 很重要
在idea右侧边栏maven中点击 m(执行maven目标)输入
其中Dfile 后面跟的是DmJdbcDriver18.jar 包存放的文件夹路径
jar包是达梦数据库中自带的
mvn install:install-file -Dfile=D:\mongodb\DM8SSSS\src\lib\DmJdbcDriver18.jar -DgroupId=dm.jdbc -DartifactId=DmJdbcDriver18 -Dversion=18 -Dpackaging=jar
3.pom.xml文件中添加依赖
第二部没有执行,第三部会报错
<!-- 达梦数据库驱动 --> <dependency> <groupId>dm.jdbc</groupId> <artifactId>DmJdbcDriver18</artifactId> <version>18</version> </dependency>
4. application.properties配置
test 我的数据库
spring.datasource.driver-class-name=dm.jdbc.driver.DmDriver spring.datasource.url=jdbc:dm://127.0.0.1:5236/test?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8 spring.datasource.username=SYSDBA spring.datasource.password=SYSDBA
5.达梦数据库数据
6.idea调用
6.1 pom.xml文件
<!-- 达梦数据库驱动 -->
<dependency>
<groupId>dm.jdbc</groupId>
<artifactId>DmJdbcDriver18</artifactId>
<version>18</version>
</dependency>
<!--springboot-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--简化代码-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>4.3</version>
</dependency>
6.2 application.properties
mybatis.mapper-locations=classpath:mapper/*.xml
6.3 启动类添加
@MapperScan(value = "com.skx.dm8ssss.mapper")
6.4 实体类
package com.skx.dm8ssss.entiy;
import lombok.Data;
import java.io.Serializable;
/**
* 员工表
* @author 阿新
*/
@Data
public class Emp implements Serializable {
private Long empId;
private String empName;
private String jobId;
private Integer salay;
private Long deptId;
}
6.5 controller
package com.skx.dm8ssss.controller;
import com.skx.dm8ssss.entiy.Emp;
import com.skx.dm8ssss.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 测试达梦数据库
* @author 阿新
*/
@RestController
@RequestMapping("skx")
public class TestController {
@Autowired
private TestService testService;
//获取数据
@GetMapping("list")
public List<Emp> getList(){
return testService.getList();
}
}
6.6 service
package com.skx.dm8ssss.service;
import com.skx.dm8ssss.entiy.Emp;
import java.util.List;
public interface TestService {
//获取数据
List<Emp> getList();
}
6.7 serviceImpl
package com.skx.dm8ssss.service.impl;
import com.skx.dm8ssss.entiy.Emp;
import com.skx.dm8ssss.mapper.TestMapper;
import com.skx.dm8ssss.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 测试达梦数据库
* @author 阿新
*/
@Service
public class TestServiceImpl implements TestService {
@Autowired
private TestMapper testMapper;
//获取数据
@Override
public List<Emp> getList() {
return testMapper.getList();
}
}
6.8 mapper
package com.skx.dm8ssss.mapper;
import com.skx.dm8ssss.entiy.Emp;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 测试达梦数据库
* @author 阿新
*/
@Repository
public interface TestMapper {
//获取数据
List<Emp> getList();
}
6.9 mapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.skx.dm8ssss.mapper.TestMapper">
<select id="getList" resultMap="sd">
select * from emp
</select>
<resultMap id="sd" type="com.skx.dm8ssss.entiy.Emp">
<id column="emp_id" jdbcType="VARCHAR" property="empId"/>
<result column="emp_name" jdbcType="VARCHAR" property="empName"/>
<result column="job_id" jdbcType="VARCHAR" property="jobId"/>
<result column="salay" jdbcType="VARCHAR" property="salay"/>
<result column="dept_id" jdbcType="VARCHAR" property="deptId"/>
</resultMap>
</mapper>
运行结果