0

I need to connect to database which is located in another server (phpmyadmin domain: nazwa.pl). By phpmyadmin website I can connect to database, so there is no problem with database. Open port is 3307 for db. I have login password host port database name so everything to connect. I tried to connect by tcp/ip then by ssh but I can't connect. And I tried it by java code, by mysql workbench, by mysql terminal, by simply as an ip address but still nothing. And in the java code error was:

SEVERE: null
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.

And my java code is:

public static int connect() {
        try {
            DriverManager.registerDriver(new Driver());
            conn = DriverManager.getConnection("jdbc:mysql://sql.******.nazwa.pl:3307/******?user=******&password=******&useUnicode=true&characterEncoding=UTF-8");
            return 1;
        } catch (SQLException ex) {
            Logger.getLogger(****.class.getName()).log(Level.SEVERE, null, ex);
            return 0;
        }
    }


public static void main(String[] args) throws JSchException {
        if (connect() == 1) {
            System.out.println("success");
        } else {
            System.out.println("error");
        }
    }

Could someone say at least where should I check my mistake?

Puck
  • 2,080
  • 4
  • 19
  • 30
  • 1
    possible duplicate of [com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure](http://stackoverflow.com/questions/2983248/com-mysql-jdbc-exceptions-jdbc4-communicationsexception-communications-link-fai) – singhakash Aug 19 '15 at 10:18
  • not exactly. I cant access database files. I mean i have access to database and tables but not to the server. and btw when im pinging to that host it shows timeout. – Javanshir Mammadov Aug 19 '15 at 10:56
  • 1
    Make sure that the server is running and port 3306 is reachable. Also by default MySQL does not allow remote connections. so make sure you change the default configuration to allow remote connections. – Avinash Reddy Aug 19 '15 at 11:27
  • Yup exactly, i found that because of security reasons 3307 port was unreachable. – Javanshir Mammadov Aug 19 '15 at 16:39

0 Answers0