【发布时间】:2020-05-04 22:48:56
【问题描述】:
我正在尝试使用 JAVA 中的数据库。 因此我下载了 MySQL,为我的 root 用户设置了密码并创建了一个模式 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)
让我有点困惑的是,消息说:(使用密码:否), 因为我在安装 MySQL 后为 root 设置了密码,并且在配置文件中指定了它。
我已经尝试解决这个问题几个小时了。 Hibernate 是 4.2.3Final,mysql-connector-java 是 8.0.20。
【问题讨论】:
标签: java mysql hibernate sqlexception