3

I Have developed an application to capture data, retrieve information,delete and also update info. The application is developed in java swing and hibernate and uses MySQL version 5.5 as a database. I tested it on my local server or local host and its working fine. So now i took it a step further trying to access the database on the remote server. Please note that also the MySQL version i use on my local server is the same as the MySQL in the remote server.

I get the following error:

Internal Exception: 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.
Error Code: 0
aizaz
  • 3,056
  • 9
  • 25
  • 57
  • 2
    Have you tried logging into the server remotely from the commandline? `mysql -u -p -h ` ought to do it. Looks to be a problem with your network/mysql config rather than the code. – Boris the Spider Apr 12 '13 at 10:21

1 Answers1

1

The problem is that your MySqlConnector/Driver can't establish a Connection to the remote server.

Check your jdbc URL and also the check if the wrong ports are used. Maybe the Mysql DB is not reachable from outside, than you can use a port forwarding with ssh, for example :

port forwarding:

ssh -L3306:127.0.0.1:3306 user@remoteServer 

than change your jdbc url to:

jdbc:mysql://localhost:3306/database

Explanation: -L port:host:hostport

Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side.
...
Whenever a connection is made to this port, the connection is forwarded over the secure channel, and a connection is made to host port hostport from the remote machine.

Source: http://www.openbsd.org/cgi-bin/man.cgi?query=ssh&sektion=1

That means you request with your MySQL JDBC Driver(jdbc url) on the local 3306 port will be forwarded to the remote server on his local 3306 port, where the Mysql Database is listing.

Zelldon
  • 5,396
  • 3
  • 34
  • 46
  • Thanks for the comments, i have found the solution to the problem, the problem was that the MySQL server didn't give permission and privileges to users trying to access the database remotely, only one user was able to access it because he was using the host machine. So we granted all users connected to the network to be able to access it. – Raymomd Masuku May 03 '13 at 09:06