Ewa Śniecińska
Ewa Śniecińska

Reputation: 91

Using online mysql database with java

I'm trying to build portfolio and I have problem with using online mysql database. I have code like this:

public class DBManager {
    public static String _host = "sql8.freesqldatabase.com";
    public static String _port = "3306";
    public static String _user = "************";
    public static String _pass = "**************";
    public static String _db = "**********";

    private static Connection connection;

    public static Connection getConnection() throws ClassNotFoundException, SQLException {
        if (connection == null) {
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://" + _host + ":" + _port + "/" + _db + "";
            connection = DriverManager.getConnection(url , _user, _pass);
        }
        return connection;
    }
  }

Some database works in workbench, before that I was working on a local database. Now I have an error like this:

Access denied for user 'sql8167592'@'host-79.173.28.129.tesatnet.pl' (using password: YES)

Upvotes: 0

Views: 211

Answers (2)

You need to execute following line on your MySQL server.

ALTER USER 'your username'@'your ip' IDENTIFIED BY 'your password';

EDIT: Remove your MySQL server ip, username and password from your question!!!

Upvotes: 1

Carlos
Carlos

Reputation: 71

Ensure the user exists in the database and the credentials are ok, if it is saying access denied, it means that the url is correct and there is a mysql server in that address

Upvotes: 1

Related Questions