skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
  3. 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?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search