Mysql Issues

kanesemp

New Member
Messages
4
Reaction score
0
Points
1
Hello,
I'm having trouble with mysql when using x10 hosting. For some reason i continue to get the error. Unable to connect to host on my cmd. Although when i run from localhost on xxamp it works fine. I'l give you a snippet of code and see if u can find the problem.

Settings
Code:
    public static final String DB_HOST = "198.91.81.2";
    public static final String DB_USER = "kanesemp_server";
    public static final String DB_PASS = "dasdasdsadasdasd";
    public static final String DB_NAME = "kanesemp_server";

Database Manager

Code:
package org.kanesempire.engine.mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import org.kanesempire.GameServer;
import org.kanesempire.Settings;

public class DatabaseManager {

    private String host;
    private String database;
    private String username;
    private String password;

    private Connection connection;
    private Statement statement;

    private boolean connected;

    public DatabaseManager() {
        this.host = Settings.DB_HOST;
        this.database = Settings.DB_NAME;
        this.username = Settings.DB_USER;
        this.password = Settings.DB_PASS;
        this.connected = false;
    }

    public void connect() {
        try {
            connection = DriverManager.getConnection("jdbc:mysql://" + host + "/" + database + "?jdbcCompliantTruncation=false", username, password);
            statement = connection.createStatement();
            GameServer.get().logger().parent("Successfully connected with " + host + "/" + database);
            connected = true;
        } catch (Exception e) {
            GameServer.get().logger().parent("Unable to connect with " + host + "/" + database + ".");
            connected = false;
        }
    }

    public ResultSet executeQuery(String query) {
        try {

            if (!connected())
                return null;

            statement = connection.createStatement();
            ResultSet results = statement.executeQuery(query);
            return results;
        } catch (Exception e) {
            GameServer.get().logger().error(e);
        }
        return null;
    }

    public int executeUpdate(String query) {
        try {

            if (!connected())
                return 0;

            statement = connection.createStatement();
            return statement.executeUpdate(query);
        } catch (Exception e) {
            GameServer.get().logger().error(e);
        }

        return 0;
    }

    public boolean connected() {
        return connected;
    }

    public Statement statement() {
        return statement;
    }

}

All help is appreciated thanks.
 

Anna

I am just me
Staff member
Messages
11,752
Reaction score
581
Points
113
I assume the values you entered in the snippet that tells what database and user to use when connecting to is just for display, as those do not match what you actually have as database name and database user in cPanel.

Try using "localhost" rather then the IP for database host, outside connections to and from the database port is blocked by the firewall, so by using the external IP of the server the connection probably hit the block there.
 

kanesemp

New Member
Messages
4
Reaction score
0
Points
1
I assume the values you entered in the snippet that tells what database and user to use when connecting to is just for display, as those do not match what you actually have as database name and database user in cPanel.

Try using "localhost" rather then the IP for database host, outside connections to and from the database port is blocked by the firewall, so by using the external IP of the server the connection probably hit the block there.

The problem is. I'm creating a website where you register then you can login game via the game client. Im using mysql to host all the users details. But as you said it is blocking the connection. I cant use localhost because i need my users to be able to register and all there details need to be stored on mysql
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
If you are trying to access MySQL directly from outside, it is blocked, period. No exceptions.

You have to access a PHP script on your account, which in turn would access the database, etc.
 

kanesemp

New Member
Messages
4
Reaction score
0
Points
1
If you are trying to access MySQL directly from outside, it is blocked, period. No exceptions.

You have to access a PHP script on your account, which in turn would access the database, etc.

Ok. Is there any chance you could message me and talk me through this?
 
Top