0

When I make a connection to my MYSQL database (hosted on phpmyadmin on a domain with hosting, not localhost), I receive an error that I'm denied access to the server entirely. What is going on? I'm not extremely familiar on how to use this libraries methods and am confused.

Connection connection;
try 
{
   connection = 
  DriverManager.getConnection("jdbc:mysql://WEBSITENAME.com/DATABASENAME0", 
   "DATABASEUSERNAME", "DATABASEPASSWORD");
   Statement sql = connection.createStatement();
   ResultSet myRs = sql.executeQuery("SELECT * FROM table");

while(myRs.next()) 
{
  System.out.println(myRs.getString("column"));
}

} catch (SQLException e) 
{
   e.printStackTrace();
}

The error provided is as follows:

java.sql.SQLException: Access denied for user 'user'@'IP ADDRESS IS LISTED HERE' (using password: YES) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835) at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:455) at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240) at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at jDgmj8pWUnXVoHZk04z9.sqlConnect.updateCommand(sqlConnect.java:12) at jDgmj8pWUnXVoHZk04z9.Driver.main(Driver.java:10)

3 Answers 3

0

I have two ideas for this:

  1. Normally you MySQL denies connections from other hosts. You have to configure that in the configuration file (see here). If you can not access the configuration file you will have to ask your admin.

  2. Additionally you should check if the port 3306 (MySQL default port for TCP connections) is even opened. If the firewall blocks that port you will not be able to connect. In Windows you could check it with telnet (if enabled):

.

telnet WEBSITENAME.com 3306

No error message (blank cmd) means connection is established.

Sign up to request clarification or add additional context in comments.

1 Comment

That looks like an answer from the server. This tells us that you where able to establish a TCP connection to the host on the used port. The problem is then in your MySQL configuration. See # 1. in my answer or justins answer.
0

Maybe one of the problem is the Server, check that the user is allowed to connect from outside the localhost, or check if you user is allowed to connect like this: user@IPAddress

1 Comment

When I do telnet I get this message any clue as to what this means: imgur.com/a/va0DurL
0

Common problem for hosted services, like hosted DBs/DBaaS nowadays. Many hosting providers default to DENY ALL and expect that no DB connections are allowed inbound from anonymous Internet IPs, aka. anything outside (a) their platform or (b) outside their subnet(s).

If the other recommended tests don't work (like telnet), ask your DB provider if they maintain a whitelist and how they provide exception. This is usually done via a self-service ticketing system for many hosting providers.

Or can you co-host your Java app on that same hosting provider? like via a basic VM/instance on the same subnet as the DB instance?

1 Comment

When I use telnet I get this message do you know what this means? imgur.com/a/va0DurL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.