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

在做Maven项目的时候出现**Exception in thread “main” java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)**错误,以下是全部提示:
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)

检查了配置文件特别是数据库配置相关的都正确,一头扎在网上找了两三个小时,看的方法都没用,因为我是想使用【逆向工程-MyBatis Generator】,用的是如下代码:
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);
}
}
因为网上找的办法都试了,都不行,我只能看自己的代码哪里有问题,看了两分钟就发现问题了,逆向工程用了File configFile = new File(“mbg.xml”);点到mbg.xml去找,因为我的mbg.xml是粘贴别人的配置,里面数据库密码没有改(因为记得Maven工程的数据库配置基本都在xxx.properties中配置,没有注意到这个),改了之后就好了。

心得:代码出错了不要直接一头扎进网上,先看看自己的代码,两分钟后还没有头绪再去百度。

猜你喜欢

转载自blog.csdn.net/qq_45443783/article/details/113415295
今日推荐