达梦数据库使用

达梦数据库使用

📑前言

本文主要是【达梦数据库】------达梦数据库简单使用的文章,如果有什么需要改进的地方还请大佬指出⛺️

🎬作者简介:大家好,我是听风与他🥇

☁️博客首页:CSDN主页听风与他

🌄每日一句:狠狠沉淀,顶峰相见

目录

本实验主要是达梦数据库增删改查的简单案例

  • 实验环境采用JDK17,使用springboot+mybatis整合达梦数据库

1.在pom.xml中导入对应的依赖

xml 复制代码
        <!--Mybatis依赖-->
       <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>3.0.2</version>
        </dependency>
<!--达梦数据库驱动-->
        <dependency>
            <groupId>com.dameng</groupId>
            <artifactId>DmJdbcDriver18</artifactId>
            <version>8.1.1.193</version>
        </dependency>
<!--jdbc驱动-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
<!--web项目依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!--lombok-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

2.配置application.yml文件

yaml 复制代码
spring:
    datasource:
        username: SYSDBA  #模式名
        password: SYSDBA  #密码
        url: jdbc:dm://localhost:5236 #达梦数据库默认端口为5236,不用更改
        driver-class-name: dm.jdbc.driver.DmDriver
server:
    port: 8080 #tomcat端口使用8080

3.实体类:Student

java 复制代码
package com.dameng.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Student {
    private int id;
    private String name;
    private int age;

}

4.接口类StudentMapper

java 复制代码
package com.dameng.mapper;

import com.dameng.pojo.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudentMapper {
    @Select("select * FROM \"student\"")
    List<Student> findAll();

    @Insert("insert INTO SYSDBA.\"student\" VALUES(#{name},#{age})")
    int insertStudent(Student student);

    @Delete("delete FROM SYSDBA.\"student\" WHERE \"student\".\"id\" == #{id}")
    int deleteStudent(int id);

    @Update("update SYSDBA.\"student\" SET SYSDBA.\"student\".\"age\" = #{age},SYSDBA.\"student\".\"name\"=#{name} WHERE \"student\".\"id\" = #{id}")
    int updateStudent(Student student);

    @Select("select * FROM SYSDBA.\"student\" WHERE \"student\".\"id\"=#{id}")
    Student findStudentById(int id);
}

测试类:DaMengApplicationTests

java 复制代码
package com.dameng;

import com.dameng.mapper.StudentMapper;
import com.dameng.pojo.Student;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
class DaMengApplicationTests {

    //注入接口对象
    @Autowired
    private StudentMapper studentMapper;

    @Test
    void contextLoads() {
        //查询所有学生
        List<Student> list = studentMapper.findAll();
        for (Student i:list){
            System.out.println(i.toString());
        }
        //根据ID查询学生
        Student student = studentMapper.findStudentById(1);
        System.out.println(student.toString());
        //添加学生
        Student student1 = new Student(0,"赵哈哈",18);
        int i = studentMapper.insertStudent(student1);
        System.out.println("i:"+i);
        //修改学生信息
        Student student2 = new Student(4,"赵七",20);
        int i1 = studentMapper.updateStudent(student2);
        System.out.println("i1:"+i1);
        //根据ID删除学生
        int i2 = studentMapper.deleteStudent(5);
        System.out.println("i2:"+i2);
    }

}

达梦数据库增删改查语法

  • 最后操作完数据库之后记得commit;不然不会立即执行。
sql 复制代码
insert INTO SYSDBA."student" VALUES('王五',20);
select * FROM SYSDBA."student";
delete FROM SYSDBA."student" WHERE "student"."id" = 3;
update SYSDBA."student" SET SYSDBA."student"."age" = 10,SYSDBA."student"."name"='张强' WHERE "student"."id" = 1;
select * FROM SYSDBA."student" WHERE "student"."id"=2;
commit;

总结

  • 达梦数据库是我国的一款优秀国产数据库,但是其自适应的DM管理工具确实没有Navicat等工具简洁明了,方便好用,但支持国产,相信达梦数据库,国产数据库会变得越来越好。

📑文章末尾

相关推荐
小超同学你好2 分钟前
OpenClaw 深度解析与源代码导读 · 第7篇:Memory 子系统——持久化、内置记忆与「人格文件」分界
数据库
2301_775148152 分钟前
如何管理RAC归档日志_共享存储中的FRA配置与双节点访问
jvm·数据库·python
RoboWizard6 分钟前
移动固态硬盘的耐用性如何,怎么判断使用寿命?
服务器·数据库·负载均衡
qq_3300379911 分钟前
php怎么实现接口请求日志记录_php如何自动记录入参出参与耗时
jvm·数据库·python
2401_8653825012 分钟前
各省政务信息化项目验收材料清单汇总及差异分析
java·开发语言·数据库
pele18 分钟前
如何用 contextmenu 事件自定义鼠标右键菜单的显示逻辑
jvm·数据库·python
2301_7735536219 分钟前
怎样禁用phpMyAdmin的控制台历史记录_防凭证与查询留存
jvm·数据库·python
m0_7436239220 分钟前
Go语言怎么实现生产者消费者_Go语言生产者消费者模式教程【精通】
jvm·数据库·python
baidu_3409988221 分钟前
CSS Grid布局如何为特定项目指定位置_使用grid-row和grid-column
jvm·数据库·python
weixin_4585801234 分钟前
如何用 blur 与 focusout 区分不冒泡与冒泡的失焦事件
jvm·数据库·python