spring-boot jdbc 连接Oracle

 
 

1.jdbc方式

1.1pom.xml文件配置
<!-- oracle mybatis -->
<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>11.2.0.2.0</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
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项目目录
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";
    }
}
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);
    }
}
image.png
1.6运行项目
运行App.java中的main方法
1.71.10访问项目
http://localhost:8080/


作者:帅哥_刷哥
链接:https://www.jianshu.com/p/7833f084d453
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值