无法连接到位于服务器上的远程数据库

时间:2022-12-04 16:29:34

I am trying to update the database table which is hosted on the server through MYSQL JDBC connector using eclipse.

我试图通过使用eclipse的MYSQL JDBC连接器更新服务器上托管的数据库表。

Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://49.**.***.115:3306/databasename";
String name = "user";
String password = "passs";

But I not able to connect to the database from my local machine. I checked all the information provided above are correct.

但我无法从本地计算机连接到数据库。我查了上面提供的所有信息都是正确的。

Can please some tell me what to i do next?

可以请一些人告诉我下一步该怎么办?

Here is the error:

这是错误:

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.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1121)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:357)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2479)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2516)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2301)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:346)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at connecttoDB.getconnection(connecttoDB.java:27)
    at updateDB.main(updateDB.java:17)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:259)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:307)
    ... 16 more

2 个解决方案

#1


1  

Have you verified that you can connect to your database server from the machine you are running this code on? It looks like there is a network problem. A good idea as a first step to diagnosing MySQL connection problems is to always try connecting from the command line to rule out networking or credentials problems

您是否已验证可以从运行此代码的计算机连接到数据库服务器?看起来有网络问题。作为诊断MySQL连接问题的第一步,一个好主意是始终尝试从命令行连接以排除网络或凭据问题

mysql -uuser -p -h49.**.***.115 databasename

where "user" is the username "databasename" is the database and "49.**.***.115" is the ip of the database server.

其中“user”是用户名“databasename”是数据库,“49。**。***。115”是数据库服务器的ip。

#2


0  

check the following steps:

检查以下步骤:

1- Ping the IP address to see if you can establish connection, There might be a firewall that is blocking incoming/outgoing communication.

1- Ping IP地址以查看是否可以建立连接。可能存在阻止传入/传出通信的防火墙。

2- Check that your ojdbc6/ojdbc14.jar is loaded in the same directory of your application.

2-检查ojdbc6 / ojdbc14.jar是否已加载到应用程序的同一目录中。

#1


1  

Have you verified that you can connect to your database server from the machine you are running this code on? It looks like there is a network problem. A good idea as a first step to diagnosing MySQL connection problems is to always try connecting from the command line to rule out networking or credentials problems

您是否已验证可以从运行此代码的计算机连接到数据库服务器?看起来有网络问题。作为诊断MySQL连接问题的第一步,一个好主意是始终尝试从命令行连接以排除网络或凭据问题

mysql -uuser -p -h49.**.***.115 databasename

where "user" is the username "databasename" is the database and "49.**.***.115" is the ip of the database server.

其中“user”是用户名“databasename”是数据库,“49。**。***。115”是数据库服务器的ip。

#2


0  

check the following steps:

检查以下步骤:

1- Ping the IP address to see if you can establish connection, There might be a firewall that is blocking incoming/outgoing communication.

1- Ping IP地址以查看是否可以建立连接。可能存在阻止传入/传出通信的防火墙。

2- Check that your ojdbc6/ojdbc14.jar is loaded in the same directory of your application.

2-检查ojdbc6 / ojdbc14.jar是否已加载到应用程序的同一目录中。