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中配置,沒有注意到這個),改了之後就好了。













心得:代碼出錯了不要直接一頭扎進網上,先看看自己的代碼,兩分鐘後還沒有頭緒再去百度。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章