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.configurationhttps://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); } }

浙公网安备 33010602011771号