0

I am finishing developing a SQL-Java application in NetBeans and the queries to the database that is in CPanel work very well when I use the same internet network from which I develop the application, but when I try to make the same queries but using another network, Internet does not allow me to make inquiries and it returns this error. I must clarify that it works on different computers as long as they are connected to the network that I mentioned

com.mysql.cj.jdbc.exceptions.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.

This is the connection code:

package users;

import java.sql.*;
import javax.sql.DataSource;
import org.apache.commons.dbcp2.BasicDataSource;


public class Conexion {
    private static final String JDBC_URL = "jdbc:mysql://67.222.16.112/users?zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&useTimezone=true&serverTimezone=UTC";
    private static final String JDBC_USER = "root";
    private static final String JDBC_PASS = "pass";
    
    public static Connection getConnection() throws SQLException //Agregamos este ultimo ya que puede generar una excepción el getConnection
    {
        return DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASS);
    }
    
    public static void close(ResultSet rs)
    {
        try {
            rs.close();
        } catch (SQLException ex) {
            ex.printStackTrace(System.out);
        }
    }
    
    public static void close(PreparedStatement stmt)
    {
        try {
            stmt.close();
        } catch (SQLException ex) {
            ex.printStackTrace(System.out);
        }
    }
    
    public static void close(Connection conn)
    {
        try {
            conn.close();
        } catch (SQLException ex) {
            ex.printStackTrace(System.out);
        }
    }
}

In the command prompt I wrote ping ip_of_my_server and I get a stable value in all the internet networks that I try, so I don't think that is it.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Piero
  • 1
  • Database servers are almost never directly accessible from the public internet and are shielded by a firewall. You will need to be in the same network, have a VPN connection or something similar to be able to connect (or - very unsafe and therefor not advisable - make the database server directly accessible from the internet). – Mark Rotteveel Nov 26 '20 at 21:11
  • So how is it that I can access from only one public network in particular and in the others it does not allow me? I configured the firewall protection in Cpanel so that specific ip's can access – Piero Nov 27 '20 at 00:14
  • That sounds like you configured the database (or a firewall) to allow connections from a specific external IP address (or range), so you won't be able to connect from another address. You would need to whitelist those other addresses as well. – Mark Rotteveel Nov 27 '20 at 09:22
  • I thought that was the problem, so I excluded the IP that I use and I get another different error so I don't think that is the problem, I was reading documentation and I read that the port of my server may already be occupied with the IP of the modem of internet that can only be connected, can that be possible? – Piero Nov 27 '20 at 16:12

0 Answers0