Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  Alexandre Santos May 7 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 –  user2488184 May 7 at 4:54

1 Answer 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';
share|improve this answer
    
I'm checking on this now... thx :) –  user2488184 May 7 at 5:06
    
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... –  user2488184 May 7 at 5:17
    
Try to connect manually from the terminal with the same credentials. –  Ayman May 7 at 5:18
    
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 –  user2488184 May 7 at 5:38
    
Wish I could give u an up vote but I don't have enough points : –  user2488184 May 7 at 5:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.