• 原创: spring boot5 与 mysql8 正确连接


    首次spring boot 配置 ,测试通过jdbc ,连接mysql8.0.1 


    1:pom.xml

        <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>8.0.11</version>
            </dependency>

    2:application.yml

    spring:
      datasource:
      #注意下行比不是mysql8.0多一个cj.
        driver-class-name: com.mysql.cj.jdbc.Driver
        username: root
        password: 123456
        url: jdbc:mysql://localhost:3306/recruit_gather?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false

    3:测试类代码

    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 SpringDataJdbc06ApplicationTests {
        @Autowired
        DataSource dataSource;
        @Test
        void contextLoads() throws SQLException {
            System.out.println("*******************");
            System.out.println(dataSource.getClass());
            Connection connection = dataSource.getConnection();
            System.out.println("connection连接:"+connection);
        }
    
    }

    4:正确显示结果


    做产品的程序,才是好的程序员!
  • 相关阅读:
    java监控Linux磁盘空间的使用情况
    报道篇
    标签详解
    selectors模块
    [Python 多线程] RLock可重入锁
    Mysql中索引的 创建,查看,删除,修改
    openpyxl模块的使用
    Oracle中row_number()、rank()、dense_rank() 的区别
    python面试题
    sql 用Group by分组后,取每组的前几条记录
  • 原文地址:https://www.cnblogs.com/asplover/p/13369675.html
Copyright © 2020-2023  润新知