java.sql.SQLNonTransientConnectionException:Could not create connection to database server解决

2022/3/7 19:15:10

本文主要是介绍java.sql.SQLNonTransientConnectionException:Could not create connection to database server解决,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.启动报Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver’. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.错误

2.访问时报java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

可以是在配置mysql时,没有指定mysql的版本,采用默认的版本,默认的版本过高,本地版本低。因为在mysql5中,jdbc的驱动是com.mysql.jdbc.Driver,而mysql6以及以上是com.mysql.cj.jdbc.Driver。所以在配置时要配置mysql版本号,主要配置数据源的驱动。

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.21</version>  **这里指定匹配版本号**
        </dependency>
spring.datasource.url=jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
**配置的驱动要和Mysql的版本一致**


这篇关于java.sql.SQLNonTransientConnectionException:Could not create connection to database server解决的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程