MyBatis数据库连接时异常

报错

在建立数据库连接时报错如下:

Error querying database. Cause: java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
The error may exist in ./mapper/UserMapper.xml
The error may involve com.xy.pojo.User.findById
The error occurred while executing a query
Cause: java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
  1. Public Key Retrieval is not allowed Warning:

    Public Key Retrieval is not allowed

    这个警告通常是由于 JDBC 连接中的某些安全设置导致的。在这里,错误信息表明了 java.sql.SQLNonTransientConnectionException 异常,其中涉及到公钥检索(Public Key Retrieval)。可能的原因是数据库连接的一些设置不被允许,可能是在连接字符串中使用了 SSL 相关的配置,而系统或数据库不允许使用公钥检索。你可能需要检查数据库连接的相关配置,确保它们符合数据库的安全策略。

  2. org.apache.ibatis.exceptions.PersistenceException: 
    ### Error querying database.  Cause: java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
    ### The error may exist in ./mapper/UserMapper.xml
    ### The error may involve com.xy.pojo.User.findById
    ### The error occurred while executing a query
    ### Cause: java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
    

    MyBatis 异常:

    MyBatis 框架捕获了一个持久化异常。从错误信息中可以看出,这个异常是由于执行数据库查询时发生了错误,原因是 java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed。这表明在执行查询时遇到了数据库连接的问题,而具体的原因是前面提到的公钥检索不被允许

解决办法:

 在db.properties数据库连接信息配置文件中的

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

加上&allowPublicKeyRetrieval=true

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

  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值