1

I started getting

java.sql.SQLException: Access denied for user 'xx@xx.xx' (using password: YES)

from a servlet when trying to add new data to a database. Irrespective of the error, the data still gets written to the database. The database has been standing for 2 years + now and no updates have been made to the database, users etc. I was wondering if anyone came across this before.

I am trying to avoid a mysql reinstall at all costs .

The mysql log file /var/log/mysql.log appears to be empty. The tomcat5.5 logs have nothing but a few info lines.

I'm running Tomcat 5.5 with MySQL 5.0.51a-24+lenny1 (Debian)

Thanks!

method8
  • 21
  • 1
  • 2
  • " Irrespective of the error, the data still gets written to the database." Does your data that is entered reflected in the database? – Abubakkar Oct 10 '12 at 10:24
  • Have you tried this link [http://dev.mysql.com/doc/refman/5.1/en/access-denied.html] – ali köksal Oct 10 '12 at 10:30
  • @Abu Yes it is still written in the database – method8 Oct 10 '12 at 10:42
  • @alikox Yes I did and everything looks fine. I am using the default port, have my grant tables set up and am able to connect remotely through a tunnel. I have localhost, %, * and xx.xx (host) usernames granted all options but I still get the error. – method8 Oct 10 '12 at 10:45
  • The password is incorrect, check it firstly. – Devart Oct 10 '12 at 11:01
  • @Devart and still manage to save the data with an incorrect password? I honestly doubt it. – method8 Oct 10 '12 at 11:44

2 Answers2

1

I had experienced the same and it is resolved by doing trim() on username and password string variables.

conn = DriverManager.getConnection(db_url, user.trim(), pass.trim());
slfan
  • 8,950
  • 115
  • 65
  • 78
user1502721
  • 93
  • 1
  • 5
0

Just try to establish the connection like this:

public static Connection getConnection() throws SQLException {
        String driver = "com.mysql.jdbc.Driver";
        String url    = "jdbc:mysql://localhost:3306/dbName"; // Change it to your database name
        String username = "root";
        String password = "yourPassword"; // Change it to your Password
        System.setProperty(driver,"");

        return DriverManager.getConnection(url,username,password);

    }
1218985
  • 7,531
  • 2
  • 25
  • 31
  • Connection is fine mate. I can do everything to the database including writing but I get an exception while at it. I know it's strange. – method8 Oct 10 '12 at 11:46