本文主要是【达梦数据库】——达梦数据库简单使用的文章,如果有什么需要改进的地方还请大佬指出⛺️
作者简介:大家好,我是听风与他
☁️博客首页:CSDN主页听风与他
每日一句:狠狠沉淀,顶峰相见
<dependency>
<groupId>org.mybatis.spring.bootgroupId>
<artifactId>mybatis-spring-boot-starterartifactId>
<version>3.0.2version>
dependency>
<dependency>
<groupId>com.damenggroupId>
<artifactId>DmJdbcDriver18artifactId>
<version>8.1.1.193version>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-jdbcartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
<dependency>
<groupId>org.projectlombokgroupId>
<artifactId>lombokartifactId>
<optional>trueoptional>
dependency>
spring:
datasource:
username: SYSDBA #模式名
password: SYSDBA #密码
url: jdbc:dm://localhost:5236 #达梦数据库默认端口为5236,不用更改
driver-class-name: dm.jdbc.driver.DmDriver
server:
port: 8080 #tomcat端口使用8080
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;
}
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);
}
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);
}
}
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;