MySQL, Connector, возвращающий "Сбой канала связи" - PullRequest
1 голос
/ 26 марта 2019

Я пытался подключить свою программу к базе данных, не относящейся к локальному хосту, поскольку она будет использоваться на другом компьютере, но я продолжаю получать сбой связи.

Это ошибка, которую я получаю:

Communications link failure
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at ContactList.SignUp.jLabelCreateMouseClicked(SignUp.java:456)
    at ContactList.SignUp.access$1300(SignUp.java:16)
    at ContactList.SignUp$8.mouseClicked(SignUp.java:164)
    at java.awt.Component.processMouseEvent(Component.java:6536)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6298)
    at java.awt.Container.processEvent(Container.java:2236)
    at java.awt.Component.dispatchEventImpl(Component.java:4889)
    at java.awt.Container.dispatchEventImpl(Container.java:2294)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4534)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
    at java.awt.Container.dispatchEventImpl(Container.java:2280)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Код работает совершенно нормально, когда я использую localhost с XAMPP.Может ли это быть ограничение OVH или некоторые настройки в MySQL.MySQL находится на Linux Ubuntu VPS.Вот код для подключения.

import java.sql.Connection;
import java.sql.DriverManager;

public class  myConnection {
    // Init Database Constants
    private static final String DATABASE_DRIVER = "com.mysql.jdbc.Driver";
    private static final String DATABASE_URL = "jdbc:mysql://54.39.145.0:3306/contact";
    private static final String USERNAME = "turtle";
    private static final String PASSWORD = "ILikeTurtles321!";
    private static final String MAX_POOL = "250";

    // Init Connection Object
    private Connection con;

    // Connect Database
    public static Connection getConnection() {
        Connection con = null;
            try {
                Class.forName(DATABASE_DRIVER);
                con = DriverManager.getConnection(DATABASE_URL, USERNAME, PASSWORD);
            } catch (Exception ex) {
                System.out.println(ex.getMessage());
            }
            return con;
        }   
    }
...