java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456) at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197) at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677) at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228) at comm.login$GetConnection.GetConnection(login.java:171) at JZS.comm.util.CheckUsers.<init>(CheckUsers.java:13) at comm.login.actionPerformed(login.java:107) at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967) at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308) at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405) at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262) at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279) at java.desktop/java.awt.Component.processMouseEvent(Component.java:6636) at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342) at java.desktop/java.awt.Component.processEvent(Component.java:6401) at java.desktop/java.awt.Container.processEvent(Container.java:2263) at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5012) at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321) at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844) at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java
时间: 2023-12-07 10:03:08 浏览: 89
这是一个 Java 异常,提示 "Public Key Retrieval is not allowed",翻译为“不允许公钥检索”。这通常出现在使用 MySQL 数据库连接时,可能是因为 MySQL 8.0.11 版本之后的驱动程序默认启用了 SSL 加密连接,而在某些情况下,这会导致公钥检索失败。
要解决这个问题,可以尝试以下两种方法:
1. 在数据库连接 URL 中添加 "allowPublicKeyRetrieval=true" 参数,例如:
jdbc:mysql://localhost:3306/mydatabase?allowPublicKeyRetrieval=true
2. 禁用 SSL 加密连接,可以在数据库连接 URL 中添加 "useSSL=false" 参数,例如:
jdbc:mysql://localhost:3306/mydatabase?useSSL=false
需要注意的是,禁用 SSL 加密连接可能会降低数据安全性,因此需要在具体情况下权衡利弊。
相关问题
java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed 是一个Java数据库连接异常,意味着连接MySQL数据库时不允许公钥检索。为了解决这个问题,可以尝试以下几种方法:
1. 修改MySQL数据库连接字符串URL,在末尾追加 "?allowPublicKeyRetrieval=true" 参数,例如:
String url = "jdbc:mysql://localhost:3306/mydatabase?allowPublicKeyRetrieval=true&useSSL=false";
2. 如果使用的是Java 8及以上版本,可以将SSL模式设置为"false",即在JDBC驱动程序中通过添加一个额外属性来关闭SSL,例如:
String url = "jdbc:mysql://localhost:3306/mydatabase?sslMode=DISABLED";
这些方法可以帮助您解决 java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed 这个异常。
SQLException : SQL state: 08001 java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed ErrorCode: 0
SQLException : SQL state: 08001 java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed ErrorCode: 0是一个数据库连接异常,表示在尝试建立与数据库的连接时,公钥检索被禁止了。这个异常通常发生在使用MySQL数据库时,当连接字符串中的useSSL参数设置为false时,会出现这个问题[^1]。
解决这个问题的方法是在连接字符串中启用SSL,或者在连接字符串中添加allowPublicKeyRetrieval参数并将其设置为true。具体的解决方法取决于你使用的数据库驱动程序和连接库的版本。
以下是一个使用JDBC连接MySQL数据库的示例代码,其中包含了解决这个问题的方法:
```java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DatabaseConnection {
public static void main(String[] args) {
String url = "jdbc:mysql://localhost:3306/enterprise_digital?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";
String username = "your_username";
String password = "your_password";
try {
Connection connection = DriverManager.getConnection(url, username, password);
System.out.println("Connected to the database successfully!");
// 进行其他数据库操作
} catch (SQLException e) {
e.printStackTrace();
}
}
}
```
请注意,上述代码中的url变量中添加了allowPublicKeyRetrieval=true参数来解决公钥检索被禁止的问题。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![epub](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)