程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了无法连接到 mysql 服务器,因为“java.sql.SQLNonTransientConnectionException:无法创建到数据库服务器的连接”大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决无法连接到 mysql 服务器,因为“java.sql.SQLNonTransientConnectionException:无法创建到数据库服务器的连接”?

开发过程中遇到无法连接到 mysql 服务器,因为“java.sql.SQLNonTransientConnectionException:无法创建到数据库服务器的连接”的问题如何解决?下面主要结合日常开发的经验,给出你关于无法连接到 mysql 服务器,因为“java.sql.SQLNonTransientConnectionException:无法创建到数据库服务器的连接”的解决方法建议,希望对你解决无法连接到 mysql 服务器,因为“java.sql.SQLNonTransientConnectionException:无法创建到数据库服务器的连接”有所启发或帮助;

这是我用来连接到服务器的代码:

String records = "",error="";
        voID connectToDatabase() {
            try {
                String ip = "";//MysqL server ip(removed due to privacy reasons)
                Class.forname("com.Mysql.cj.jdbc.Driver").newInstance();
                Connection connection = DriveRMANager.getConnection("jdbc:MysqL://" + ip +":3306/androIDdb?user=andro&password=andro");
                Statement statement = connection.createStatement();
                ResultSet resultSet = statement.executequery("SELECT * FROM maintable");
                while (resultSet.next()) {
                    records += resultSet.getString(1) + " " + resultSet.getString(2) + "\n";
                }
                System.out.println(records);
            } catch (Exception E) {
                error = e.toString();
                System.out.println(error);
            }
        }

异常:

java.sql.sqlNonTransIEntconnectionexception: Could not create connection to database server.
@H_924_2@my.ini 文件:

[MysqLd]
basedir=C:\\Program files\\MysqL\\MysqL Server 8.0
datadir=C:\\Program files\\MysqL\\MysqL Server 8.0\\data
bind-address = *MysqL server iP*

我使用 MysqL 服务器 8.0.24 和 jdbc 8.0.24

UPD:我不知道为什么,但它在我安装 jdbc 5.0.41 后开始工作

解决方法

我在 MySQL 8.0.23 和 jdbc 连接器 8.0.24 上遇到了同样的错误。在我看来,通过在字符串中添加参数 `&allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=GMT%2B9:00&rewriteBatchedStatements=true&connectionTimeZone=SERVER' 连接成功。有关详细信息,请参阅发行说明。

    @H_441_30@mySQL :: MySQL Connector/J 8.0 Release Notes :: Changes in MySQL Connector/J 8.0.23 (2021-01-18,General Availability)

希望对你有帮助。

大佬总结

以上是大佬教程为你收集整理的无法连接到 mysql 服务器,因为“java.sql.SQLNonTransientConnectionException:无法创建到数据库服务器的连接”全部内容,希望文章能够帮你解决无法连接到 mysql 服务器,因为“java.sql.SQLNonTransientConnectionException:无法创建到数据库服务器的连接”所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。