Spring boot 之Oracle JDBC

1、在IDEA创建spring boot 项目

2、下载oracle驱动jar包

查询oracle的版本,下载对应的包

 

 下载方法如下 

https://mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/

3、导入包并配置pom.xml

 

 

 

 

        <dependency>
            <groupId>com.ojdbc6</groupId>
            <artifactId>com.ojdbc6</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/ojdbc6.jar</systemPath>
        </dependency>

4、配置数据库连接信息

server.port=9190

spring.datasource.url=jdbc:oracle:thin:@localhost:1521/ORCL.TEST
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.username=lytest
spring.datasource.password=111111

 

5、写接口

package com.olddog.tongliao.controllers;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
public class test2 {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @ResponseBody
    @RequestMapping("/test2")
    public List<Map<String, Object>> hello() {
        try {
            String sql = "select * from TL.V_SEARCH_AREA_LIST";
            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
            return list;
        }catch (Exception ee){
            throw ee;
        }
    }
}

6、打包上线并测试

 

posted on 2021-07-20 19:03  苹果园dog  阅读(319)  评论(0编辑  收藏  举报

导航