0

I've seen this question a lot on the forum but all of the issues were slightly different so as not to apply so I'm going to ask it again. I've created a java web application that uses mysql as a backend. The mysql database is installed on a separate server from the web server. In mysql, I've created a user for my web application, defining the user's password, granted the user permissions and also define which IP Address the user may connect from. I've placed the database user info into the jdbc.properties file of the web application. The web application utilizes the Spring framework and when running on the web server it is able to connect to the database fine when Spring is managing the connection. However, I have one piece of code that requires me to manually connect to the database using jdbc code and when this piece of code runs, using the exact same database connection info as the spring-managed connection, I get the error:

<b>java.sql.SQLException: Access denied for user 'someuser'@'127.101.5.73' (

using password: YES)

I was pretty sure everything was correct since it works like a charm in my dev setup but it's not working in the test environment so something has got to be wrong. The code below is the code that I use to try to connect to the database. The propertiesMap variable holds the database info that was read from the jdbc.properties file:

private static void getResultSet(Map<String, String> propertiesMap, String sql) throws Exception {
try {
  // load the MySQL driver
  Class.forName("com.mysql.jdbc.Driver");

  // get the connection
  connect = DriverManager.getConnection(propertiesMap.get("jdbc.prod.url") + "?user=" 
          + propertiesMap.get("jdbc.prod.username") + "&password=" + propertiesMap.get("jdbc.prod.password"));

  // create the statement
  statement = connect.createStatement();

  // execute sql statement
  resultSet = statement.executeQuery(sql);

} catch (Exception e) {
  throw e;
}

}

The connection url in the above code resolves to:

jdbc:mysql://192.168.1.55:3306/somedatabase?user=someuser&password=somepassword

I'd appreciate any help anyone can offer.

2
  • So many things could be wrong. Check if the user "someuser" has access via this connection. Try using mysql connector and connecting to the remote server using the credentials provided. Commented May 7, 2014 at 4:35
  • someuser has access. The application injects the exact same user and password from jdbc.properties file into the driver manager bean setup in the spring application context... all of the DAO's connect to fine to the database and pull information. It's just this manual piece that won't work Commented May 7, 2014 at 4:54

1 Answer 1

1

From the exception you can tell that the code is behaving correctly. Try to grant the user access to the database:

GRANT ALL ON somedatabase.* TO 'username'@'127.101.5.73';
Sign up to request clarification or add additional context in comments.

6 Comments

It didn't work. I've read the mysql documentation and it states that that specific error message signifies that the password is incorrect but the credentials are correct. Hmmm...
Try to connect manually from the terminal with the same credentials.
I wasn't able to log into the mysql server that way... interesting. I've been managing the databas server thru webmin so I never knew the login could succeed in the application but fail at command line. It appears to be failing because there is an amperstand (&) in the password. Thx for your help!!! Hopefully removing this special character from the password will do the trick :D
Wish I could give u an up vote but I don't have enough points :
No worries :) The important thing is that we all share knowledge and benefit
|

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.