JdbcTemplate

  • https://zhuanlan.zhihu.com/p/569597103
  • 引入依赖
    <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
    <groupId>com.oracle.database.jdbc</groupId>
    <artifactId>ojdbc8</artifactId>
    <version>19.8.0.0</version>
    </dependency>
  • 加入datasource配置 
    Spring:
      datasource:
        driver-class-name: oracle.jdbc.OracleDriver
        url: jdbc:oracle:thin:@//localhost:1521/xe
    username: system   
       password: admin

    请参考Spring官方文档:
    https://docs.spring.io/spring-boot/reference/data/sql.html#data.sql.datasource.configuration

     https://docs.spring.io/spring-boot/reference/data/sql.html#data.sql.datasource.configuration

  • @Component
    public class Handler {
        @Autowired
        JdbcTemplate jdbcTemplate;
    
        public void execute() {
    
            List str = jdbcTemplate.queryForList("select * from table");
            System.out.println(str);
        }
    }

     

posted @ 2024-07-22 16:10  A-P-I  阅读(9)  评论(0)    收藏  举报