Using Mysql database for connecting to java

Website URL


Error Message

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.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(
at com.mysql.cj.jdbc.ConnectionImpl.(
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(
at java.sql/java.sql.DriverManager.getConnection(
at java.sql/java.sql.DriverManager.getConnection(
at DatabaseConnection.getConnection(
at UserDAOImpl.(
at LoginFormController.(
at Main$
at java.desktop/java.awt.event.InvocationEvent.dispatch(
at java.desktop/java.awt.EventQueue.dispatchEventImpl(
at java.desktop/java.awt.EventQueue$
at java.desktop/java.awt.EventQueue$
at java.base/
at java.base/$JavaSecurityAccessImpl.doIntersectionPrivilege(
at java.desktop/java.awt.EventQueue.dispatchEvent(
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(
at java.desktop/java.awt.EventDispatchThread.pumpEvents(
at java.desktop/java.awt.EventDispatchThread.pumpEvents(
at java.desktop/
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

Other Information

this is my code for Databaseconnection:

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

public class DatabaseConnection {
    private static final String URL = "jdbc:mysql://";
    private static final String USERNAME = "if0_36448072";
    private static final String PASSWORD = "{mypass}";
    private static Connection connection;

    public static Connection getConnection() {
        if (connection == null) {
            try {
                connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
            } catch (SQLException e) {
        return connection;

    public static void closeConnection() {
        if (connection != null) {
            try {
            } catch (SQLException e) {

I dont think java works here.


No like I am actually creating an for testing how database connection works

Then your test is successful and you have your answer. The result of the test is that it doesn’t work.

I think you’re missing the point. Our database servers are not web accessible. You cannot connect to our databases from anywhere other than our hosting.

And since we don’t provide the ability to run Java on our hosting, you must be running it elsewhere. And you will not be able to reach our databases from wherever this “elsewhere” is.


It might be possible to write a php script hosted on your website to act as a middle-man between your external app and your mysql data but that’s another level of complexity

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.