问题描述
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).log4j:WARN Please initialize the log4j system properly.Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connectionat org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142)at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85)at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1354)at test.Test.main(Test.java:18)Caused by: 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:2985)at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:885)at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3421)at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1247)at com.mysql.jdbc.Connection.createNewIO(Connection.java:2775)at com.mysql.jdbc.Connection.<init>(Connection.java:1555)at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)at java.sql.DriverManager.getConnection(DriverManager.java:582)at java.sql.DriverManager.getConnection(DriverManager.java:154)at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)... 5 more 问题补充:谢谢,对我又点启发,我再试试
解决方案
用户名密码不对,或者你的ROOT的用了个空白密码了吧,给ROOT加个密码先,或者创建一个新的用户专门让这个用户登录
解决方案二:
首先确认下数据库的用户名密码都是正确的;其次看下hibernate是否需配置log4j,或者是否需要导入log4j的包!good luck!
解决方案三:
root用户对应的密码没输正确吧。