Java. SQL. SQLException: Access denied for user 'root, password = www.bkjia.com '@ 'localhost' (using password: NO)
Today, when I tried to write the code for connecting to the database, I encountered a problem. It took only half a day to find the cause of the error.
String driver = "com. mysql. jdbc. Driver ";
String url = "jdbc: mysql: // localhost: 3306/paper? User = root, password = www.bkjia.com ";
Class. forName (driver );
This. connection = DriverManager. getConnection (url );
The error "user = root, password = www.bkjia.com" is reported in this Code. "," cannot be used for connection, but "&" is used. the default "&" is used to separate the user name and password.
As a matter of fact, I think there is another way of writing that is not prone to errors: DriverManager. getConnection (url, user, password); this method writes them separately.