spring-boot jdbc 连接Oracle

1.jdbc方式

1.1pom.xml文件配置



    com.oracle
    ojdbc6
    11.2.0.2.0


    org.springframework.boot
    spring-boot-starter-jdbc

spring-boot jdbc 连接Oracle_第1张图片
image.png

1.2application.properties配置

spring.datasource.url=jdbc:oracle:thin:@localhost:1521:orcl
spring.datasource.username=admin
spring.datasource.password=admin
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.max-idle=10
spring.datasource.max-wait=10000
spring.datasource.min-idle=5
spring.datasource.initial-size=5

1.3项目目录

spring-boot jdbc 连接Oracle_第2张图片
image.png

1.4OneController.java

package com.shuai.spring_boot_1.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class OneController {
    
    @Autowired
    private JdbcTemplate jdbcTemplate;
    
    @RequestMapping("/")
    @ResponseBody
    public String index(){
        
        String sql = "insert into users (id,name) values (1,'zhangsan')";
        jdbcTemplate.execute(sql);
        System.out.println("执行完成");
        
        return "hello spring boot";
    }
}
spring-boot jdbc 连接Oracle_第3张图片
image.png

1.5App.java

package com.shuai.spring_boot_1;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class App {
    
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}
spring-boot jdbc 连接Oracle_第4张图片
image.png

1.6运行项目

运行App.java中的main方法

1.71.10访问项目

http://localhost:8080/

你可能感兴趣的:(spring-boot jdbc 连接Oracle)