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