尝试整合JDBC
spring: datasource: username: root password: 123456 url: jdbc:mysql://localhost:3306/mybatis?useSSL=true&userUniceode=true&characterEncoding=utf8 driver-class-name: com.mysql.cj.jdbc.Driver
package com.example.springboot04date; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; @SpringBootTest class SpringBoot04DateApplicationTests { @Autowired //注入数据 DataSource dataSource; @Test void contextLoads() throws SQLException { //查看默认的数据源 System.out.println(dataSource.getClass());//class com.zaxxer.hikari.HikariDataSource //获取数据库连接 Connection connection = dataSource.getConnection(); //Template //CURD豆子SpringBoot中封装好了,拿来即用 System.out.println(connection); //关闭 connection.close(); } }
标签:17,Spring,sql,Boot,connection,dataSource,import,org,com From: https://www.cnblogs.com/bzsc/p/18044726