Could not open JDBC Connection for transaction; nested exception is org.apache.commons.dbcp.SQLNeste

 

报错信息:Could not open JDBC Connection for transaction; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server.)java

问题来源mysql-connecter-java 版本太低 若是你mysql的版本是mysql 8.0+ 而你的mysql-connecter-java 为5.x.x的时候就会报错这个错误 因此若是你是maven环境 更换以下版本 还要更换数据库链接配置mysql

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.11</version>
</dependency>

数据库链接配置更新sql

driverClassName 配置 com.mysql.jdbc.Driver 替换为 com.mysql.cj.jdbc.Driver
url 配置 增长为 ?serverTimezone=UTC&amp;useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false"

效果:数据库

driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/XXXX?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false
username=root
password=

 拓展apache

在上面配置:服务器

url=jdbc:mysql://localhost:3306/XXXX?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false

中若是maven

serverTimezone配置为UTC 那么会比中国早八个小时 若是在中国你能够配置成ShangHai或者Hongkong 以下面所示
url=jdbc:mysql://localhost:3306/test?serverTimezone=Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false



报错信息: java.sql.SQLException: Unknown system variable 'query_cache_size'url

问题来源mysql-connecter-java 版本太低 若是你mysql的版本是mysql 8.0+ 而你的mysql-connecter-java 为6.x.x的就会报错这个错误 因此若是你是maven环境 更换以下版本就行了spa

若是错误依然为解决请参考上面更换数据库链接配置code

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.11</version>
</dependency>

 

一些小提示

不推荐不使用服务器身份验证来创建SSL链接。

若是未明确设置,MySQL 5.5.45+, 5.6.26+ and 5.7.6+版本默认要求创建SSL链接。

为了符合当前不使用SSL链接的应用程序,verifyServerCertificate属性设置为’false’。

若是你不须要使用SSL链接,你须要经过设置useSSL=false来显式禁用SSL链接。

若是你须要用SSL链接,就要为服务器证书验证提供信任库,并设置useSSL=true。

相关文章
相关标签/搜索