添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

解决Failed to obtain JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException

最新推荐文章于 2023-07-02 00:30:26 发布
最新推荐文章于 2023-07-02 00:30:26 发布

先上错误截图

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Public Key Retrieval is not allowed)
### The error may exist in cn/hy/mapper/UserMapper.xml
### The error may involve cn.hy.mapper.UserMapper.selectUserById
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Public Key Retrieval is not allowed)

背景:我使用dbcp配置数据库连接池

按照这个提示,大概就是连接池问题,那么我们看配置文件

  <!--    dbcp配置-->
    <context:property-placeholder location="classpath:db.properties"/>
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${driver}"/>
        <property name="url" value="${url}"/>
        <property name="username" value="${username}"/>
        <property name="password" value="${password}"/>
        <property name="maxActive" value="10" />
        <property name="maxIdle" value="5" />
    </bean>

经过一系列排除,原来是username出现问题
我们用dbcp去配置数据库连接池时,${username}并非db.properties文件中的username。而是映射到了系统环境变量中的username
所以我们在配置db.properties时,通常都是以jdbc或db作为前缀,这样就可以避免重命的问题.
在修改之后,测试一下,没有问题
在这里插入图片描述

解决Failed to obtain JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException 先上错误截图org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nes org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted at org.springframework.jdbc.dataso
org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection异常问题解决; spring boot ,mybatis ,sqlserver 2000,STS3.9 、jdk8 ,sqljdbc4 1.0-2000的一个环境启动时,调用查询Dao时报错。 具体错误如下:
文章目录报错环境原因解决参考 配置好了nacos的application.properties,成功启动了mysql,运行nacos的mysql脚本生成了对应的数据库。启动nacos连接mysql时报错。 报错:org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNeste
2.下载ojdbc8.jar 3.cmd执行 mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc8 -Dversion=12.2.0.1 -Dpackaging=jar -Dfile=C:/ojdbc8.jar
使用springboot与mybatis时,总是遇到数据库无法连接的错误,将解决方法记录如下。 Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; spring.MyBatisExceptionTranslator.translateExceptionIfPossible ibatis.exceptions.ExceptionFactory.wrap
nested exception is org.apache.ibatis.exceptions.PersistenceException Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection
eption is java.sql.sqlexception: cannot create poolableconnectionfactory (could not create connection to database server. attempted reconnect 3 times. giving up.) 这是一个MyBatis和Spring集成的异常,原因是查询数据库时出现了错误。具体原因是无法获取JDBC连接,可能是由于连接数据库服务器时出现了问题。已经尝试重新连接3次,但仍然无法连接。
解决Failed to obtain JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException
解决AttributeError: module ‘win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x9‘ has no attribu ZhangAK_exe: 为啥我删了后出现了新问题 解决java.lang.IllegalStateException: Found multiple @SpringBootConfiguration annotated classes [Generi yimiygk: 你有答案了么 基于聚类实现图像分割实例 filePath写什么? 解决2021版本idea内存不足问题 Guann_: 在其他博客里看到有人因为改了源文件idea64.exe.vmoptions导致idea根本打不开的。。不敢轻举妄动啊 记录在conda创建虚拟环境遇到的问题 岚-岚岚岚岚岚: 为什么博主跑题了,题目里的问题解决了吗