编程人 cdmana.com

Exception in thread “main“ java.sql.SQLException : Access denied for user ‘root‘@‘localhost‘ (using p

Doing it Maven When the project comes up **Exception in thread “main” java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)** error , Here are all the tips :
Exception in thread “main” java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:868)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3340)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1238)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2743)
at com.mysql.jdbc.Connection.(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at org.mybatis.generator.internal.JDBCConnectionFactory.getConnection(JDBCConnectionFactory.java:84)
at org.mybatis.generator.config.Context.getConnection(Context.java:753)
at org.mybatis.generator.config.Context.introspectTables(Context.java:631)
at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:257)
at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:139)
at com.atguigu.crud.test.MBGTest.main(MBGTest.java:23)














Check the configuration file, especially the database configuration , I spent two or three hours on the Internet , There's no way to look , Because I want to use 【 Reverse engineering -MyBatis Generator】, Using the following code :
public class MBGTest {
public static void main(String[] args) throws Exception {
List warnings = new ArrayList();
boolean overwrite = true;
File configFile = new File(“mbg.xml”);
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
callback, warnings);
myBatisGenerator.generate(null);
}
}
Because I tried all the methods I found on the Internet , Neither. , I can only see what's wrong with my code , After watching it for two minutes, I found the problem , Reverse engineering uses File configFile = new File(“mbg.xml”); Point to mbg.xml Look for , Because of my mbg.xml Paste someone else's configuration , The database password has not been changed ( Because remember Maven The database configuration of the project is basically xxx.properties Middle configuration , Didn't notice this ), It will be better after the change .













Experience : If the code goes wrong, don't plunge into the Internet , Take a look at your own code first , Two minutes later, I don't have a clue to go to Baidu .

Scroll to Top