[英]java.net.ConnectException: Connection refused
I am trying to connect to a mysql database on remote server and whenever I try to run the code it is giving me connection refused exception. 我试图连接到远程服务器上的mysql数据库,并且每当我尝试运行代码时,它都会给我拒绝连接的异常。
Connection con = null;
String driver = "com.mysql.jdbc.Driver";
String url1="jdbc:mysql://IPADDRESS:3306/";
String db = "hola";
String dbUser = "root";
String dbPasswd = "root";
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url1+db, dbUser, dbPasswd);
System.out.println("Database Connection Established");
Also, when I telnet with that IP on a port 3306 it is giving me connection refused. 另外,当我使用端口3306上的IP进行Telnet时,连接被拒绝。 How can I make sure that my server listens to connection over port 3306? 如何确保服务器侦听端口3306上的连接?
java.net.ConnectException: Connection refused
意味着您输入的IP地址或端口号不正确!
There is nothing listening at that IP:port. 在该IP:port上没有监听。 Check that the IP:port is correct, that MySQL is installed there, on that port, and that it is running. 检查IP:port是否正确,在该端口上是否已安装MySQL,以及它是否正在运行。
Contrary to other answers here, it has nothing to do with the user name, password, or permissions, and almost certainly nothing to do with the firewall either unless you have an antique. 与这里的其他答案相反,它与用户名,密码或权限无关,并且几乎可以肯定与防火墙无关,除非您有古董。
In general, when you are getting java.net.ConnectException: Connection refused
often it is because of the following reasons: 通常,当您获取java.net.ConnectException: Connection refused
经常java.net.ConnectException: Connection refused
是由于以下原因:
I've found the solution for the problem. 我找到了解决问题的方法。 My server was not listening to connections over the port 3306 and I made necessary configurations 我的服务器未监听端口3306上的连接,因此我进行了必要的配置
Thank you all 谢谢你们
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.