gpt4 book ai didi

尝试在 MySQL 中连接时出现 java.net.ConnectException

转载 作者:行者123 更新时间:2023-11-29 06:03:49 25 4
gpt4 key购买 nike

<分区>

我尝试从一个 servlet 连接我的数据库 (MySQL),但我得到了连接被拒绝错误。我读过类似的问题,如 this .然而:

You have not started your server.

在我的本地服务器(Ubuntu 服务器 16.04)中,IP 192.168.0.4 安装了 MySQL 服务器MySQL Server 正在运行,命令 service mysql status 给出以下输出:

Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2017-03-21 11:50:56 EET; 1 weeks 1 days ago
Main PID: 1209 (mysqld)


You are trying to connect to the wrong IP/port.

MySQL 正在监听端口 3306,作为命令 netstat -an | grep 3306.给出以下输出

tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN


A firewall is blocking your connection before it reaches your server.

服务器的防火墙被禁用,如ufw status

Status: inactive

我也禁用了我的 PC 的防火墙,但它没有解决连接错误。


Your server has too many pending connections waiting to be accepted.

我的服务器是全新安装的,没有任何挂起的连接。


Your server is not listening for connections.

我运行commnand nmap -sT -O localhost 我得到:

Not shown: 993 closed ports
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
25/tcp open smtp
80/tcp open http
110/tcp open pop3
143/tcp open imap
3306/tcp open mysql

NETBEANS

我和服务器我们在同一个网络中。我处理与数据库通信的 Java 类包含:

private final String WEBAPP_DB = "jdbc:mysql://192.168.0.4:3306/myDataBase";
private final String JDBC_DRIVER="com.mysql.jdbc.Driver";
private final String USERNAME = "myUserName";
private final String PASSWORD = "myPassWord";

Connection c = null;
PreparedStatement stm = null;

sq = "SELECT * FROM Machines";
try {
Class.forName(JDBC_DRIVER);
c = DriverManager.getConnection(WEBAPP_DB, USERNAME, PASSWORD);
stm = c.prepareStatement(sq);
ResultSet rs = stm.executeQuery();

while(rs.next()){
System.out.println("Machine = " + rs.getInt("id"));
}

} catch (SQLException e) {
e.printStackTrace();
} finally {
if (stm != null) {
stm.close();
}
if (c != null) {
c.close();
}
}

我得到的一些错误是

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
...
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
...
Caused by: java.net.ConnectException: Connection refused: connect

任何提示可能是什么问题?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com