IT俱乐部 Oracle Oracle数据库基本操作及Spring整合Oracle数据库详解

Oracle数据库基本操作及Spring整合Oracle数据库详解

一、Oracle数据库介绍

1、Oracle: 中文意思:神谕 是由美国Oracle公司开发的一个面向对象、关系型大型数据库。

版本:2.0 3.0 ….. 9i(Internet) 10g(g:网格) 11g 12C

2、Oracle数据库的特点

大型的、安全性高、费用高

3、Oracle数据库的基本操作(权限)

默认三个角色:Sys (超级) System(DBA:数据库管理员) scott(学习账号) tiger

所有的操作都必须有权限:System

Sql:

DDL: 数据定义语言(create drop alter)

DCL: 数据控制语言(Grant:授权  Revoke:收回  Deny:拒绝)

例如:授予某个用户的select权限:

1
2
3
4
Grant select on 表名 to 用户
Grant select,update,delete on 表名 to 用户
 
Revoke select on 表名 from 用户

DML:数据操作语言:update delete insert

DQL: 数据查询语言: select

TCL:  事务控制语言: commit  rollback

创建表空间

删除表空间

创建用户

授权:授权abc用户可以连接(connect)且操作资源(resouce)

二、SpringBoot整合oracle

导入依赖

1
4.0.0com.exampleoracle-test0.0.1-SNAPSHOToracle-testoracle-test17UTF-8UTF-83.0.2org.springframework.bootspring-boot-starter-data-jpaorg.springframework.bootspring-boot-starter-webcn.easyprojectorai18n12.1.0.2.0org.springframework.bootspring-boot-devtoolsruntimetruecom.oracle.database.jdbcojdbc8runtimeorg.projectlomboklomboktrueorg.springframework.bootspring-boot-starter-testtestorg.springframework.bootspring-boot-dependencies${spring-boot.version}pomimportorg.apache.maven.pluginsmaven-compiler-plugin3.8.11717UTF-8org.springframework.bootspring-boot-maven-plugin${spring-boot.version}com.song.OracleTestApplicationtruerepackagerepackage

配置文件

1
2
3
4
5
6
7
8
9
10
11
spring:
  datasource:
    username: abc
    password: abc123
    driver-class-name: oracle.jdbc.driver.OracleDriver
    url: jdbc:oracle:thin:@localhost:1521:orcl
  jpa:
    show-sql: true
    hibernate:
      ddl-auto: update
    database: oracle

实体类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package com.damo.pojo;
 
import jakarta.persistence.*;
import lombok.Data;
 
/**
 * @author Damo
 * @date 2024/10/24 0018
 * @time 16:02
 */
@Entity
@Table(name = "t_book")
@Data
public class Book {
 
    @Id @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Integer id;
 
    private String title;
    private String author;
    private Integer price;
}

Dao

1
2
public interface BookDao extends JpaRepository {
}

测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.damo;
 
import com.damo.dao.BookDao;
import com.damo.pojo.Book;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
 
@SpringBootTest
class OracleTestApplicationTests {
 
    @Resource
    private BookDao bookService;
    @Test
    void contextLoads() {
        //新增
        Book book  =new Book();
        book.setAuthor("zhangs");
        book.setPrice(100);
        book.setTitle("测试");
        this.bookService.save(book);
    }
 
    @Test
    public void list(){
        //查询列表
        this.bookService.findAll().forEach(System.out::println);
    }
    @Test
    public void delete(){
        //删除
        this.bookService.deleteById(1);
    }
    @Test
    public void update(){
        //修改
        Book book = this.bookService.findById(1).get();
        book.setTitle("xxx");
        book.setPrice(200);
        this.bookService.saveAndFlush(book);
    }
}

总结 

到此这篇关于Oracle数据库基本操作及Spring整合Oracle数据库的文章就介绍到这了,更多相关Spring整合Oracle内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章希望大家以后多多支持IT俱乐部!

本文收集自网络,不代表IT俱乐部立场,转载请注明出处。https://www.2it.club/database/oracle/15529.html
上一篇
下一篇
联系我们

联系我们

在线咨询: QQ交谈

邮箱: 1120393934@qq.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部