Hibernate+MySQL:无法打开连接



我正在尝试使用JAVA中的数据库。因此,我下载了MySQL,为我的根用户设置了密码,并创建了一个模式JH。数据库正在localhost端口3306上运行。

现在我想使用hibernate来持久化和访问数据。我的hibernate.cfg.xml看起来像这样:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.current_session_context_class">
thread
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/JH
</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.username">
root
</property>
<property name="conenction.password">
Password
</property> 
<property name="dialect">
org.hibernate.dialect.MySQL5Dialect
</property>
<mapping resource="Movie.hbm.xml" />
</session-factory>
</hibernate-configuration>

我检查了数据库JH是否在带有mysqlshow的3306端口上运行。

现在,当我尝试使用建立到数据库的连接时

Session session = sessionFactory.getCurrentSession();
session.beginTransaction();

beginTransaction方法抛出GenericJDBCException:无法打开连接:

Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost' (usi
ng password: NO)

让我有点困惑的是,消息上写着:(使用密码:NO(,因为我在安装MySQL后为root设置了密码,并且在配置文件中指定了密码。

我已经试着解决这个问题好几个小时了。Hibernate是4.2.3Final,mysql连接器java是8.0.20。

在hibernate.cfg.xml 中将"conunction.password"更改为"connection.password

最新更新