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.

报错信息: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.)

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

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

数据库连接配置更新

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=

拓展

在上面配置:

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

中如果

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‘

问题来源mysql-connecter-java 版本过低 如果你mysql的版本是mysql 8.0+ 而你的mysql-connecter-java 为6.x.x的就会报错这个错误 所以如果你是maven环境 更换如下版本就好了

如果错误依然为解决请参考上面更换数据库连接配置

<!-- 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。

 

原文地址:https://www.cnblogs.com/hwcs/p/9785020.html

时间: 2024-08-10 09:18:37

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.的相关文章

Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException:

七月 17, 2014 4:56:01 下午 org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [dispatcher] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemExc

jdbc连接oracle时报错 Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableC

错误: Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure Last packet sent

org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class

org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '${jdbc.driverClassName}' at org.springfra

org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class &#39;com.microsoft.sqlserver.jdbc.SQLServerDriver &#39;

问题摘要: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.microsoft.sqlserver.jdbc.SQLServerDriver ' 原因:配置文件drive

HTTP Status 500 - Could not open JDBC Connection for transaction; nested exception is java.lang.NoCl

HTTP Status 500 - Could not open JDBC Connection for transaction; nested exception is java.lang.NoClassDefFoundError: com/mchange/v2/sql/SqlUtils type Exception report message Could not open JDBC Connection for transaction; nested exception is java.l

Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: Connectio

严重: StandardWrapper.Throwableorg.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!

spring+mybatis整合,org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class &#39;${jdbc.driverClassName}

在使用spring+mybatis时会出现Cannot load JDBC driver class ${jdbc.driverClassName}之类的出错. 原因是在spring里使用org.mybatis.spring.mapper.MapperScannerConfigurer 进行自动扫描的时候,设置了sqlSessionFactory 的话,可能会导致PropertyPlaceholderConfigurer失效,也就是用${jdbc.username}这样之类的表达式,将无法获取到

通过dbcp链接池对数据库操作报 Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)--解决方案

org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Atte

org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Cannot open con

org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Cannot open connection org.springframework.orm.hibernate3.Hiberna