In command line when I type:
mysql -u ebtam -p
I see text:
Enter password:
When I simply press ENTER, I see the mysql> , so I am successfully logged in without a password.
In Java however when I try:
private static final String DEFAULT_DRIVER = "com.mysql.jdbc.Driver";
private static final String DEFAULT_URL = "jdbc:mysql://localhost:3306/ebtam";
private static final String DEFAULT_USERNAME = "ebtam";
private static final String DEFAULT_PASSWORD = "";
I am getting:
java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
I know my code is fine because when I try
private static final String DEFAULT_USERNAME = "root";
private static final String DEFAULT_PASSWORD = "myPasswordHere";
Everything works fine..
What is it that I am doing wrong?
Pass null as password instead of an empty String. That should make it work.
private static final String DEFAULT_DRIVER = "com.mysql.jdbc.Driver";
private static final String DEFAULT_URL = "jdbc:mysql://localhost:3306/ebtam";
private static final String DEFAULT_USERNAME = "ebtam";
private static final String DEFAULT_PASSWORD = null;
try this it may it will help full for you
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.