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?