0

I am trying to connect to mysql database from my java application. I am using Connector J driver. I can connect to mysql from 'cmd' and netbeans but when I try to connect to the database using java code it shows error 1045 sqlstate 28000 Access denied for user 'sayeed'@'localhost'. I've searched various topics like: Access denied for user 'root'@'localhost' (using password: YES) (Mysql::Error) and How to connect NetBeans to MySQL database? but none of them worked for me.

try {
    Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
    System.out.print("Driver not Found");
}

try {
    connect = DriverManager.getConnection(
            "jdbc:mysql://localhost:3306/sqltest", "sayeed", "miracle");
    System.out.printf("okay");
} catch (SQLException e) {
    System.out.print(e.getSQLState() + " " + e.getErrorCode());
    System.out.print("\n" + e.getMessage() + "\n");
}

This shows the error:

28000 1045
Access denied for user 'sayeed'@'localhost' (using password: YES)

using 'cmd' i can connect to mysql accessing database from cmd and i can connect to the database using netbeans new connection wizard. connecting to database from netbeans

Note: I have granted all privileges to 'sayeed' my user table in mysql database shows (all privileges for sayeed)

Can anyone tell me what i'm doing wrong?

5
  • You'll be better off if you print the stack trace in your catch blocks rather than selectively choosing messages. Look at this question and scroll down to the 3rd answer by @Doug: stackoverflow.com/questions/16325115/… Commented Apr 22, 2016 at 12:17
  • my root password is blank Commented Apr 22, 2016 at 12:29
  • You aren't using the root password to log in via Java (and you shouldn't under any circumstance). I see username "sayeed" and password "miracle". That's a different user from root. Did you GRANT that user access? sayeed != root. Commented Apr 22, 2016 at 12:31
  • @duffymo, yes i have granted all privileges for database sqltest to sayeed.In fact, 'sayeed' has all the privileges 'root' has (global and for 'sqltest'). Commented Apr 22, 2016 at 13:01
  • @duffymo, sayeed@localhost Commented Apr 22, 2016 at 13:15

0

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.