Hibernate + MySQL: 无法打开连接
Hibernate + MySQL: Could not open connection
我正在尝试使用 JAVA 中的数据库。
因此我下载了 MySQL,为我的 root 用户设置了密码并创建了一个模式 JH。
数据库位于本地主机端口 3306 上的 运行。
现在我想使用休眠来持久化和访问数据。
我的 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 是 运行 在端口 3306 上 mysqlshow.
现在,当我尝试使用以下方法建立与数据库的连接时:
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
beginTransaction 方法抛出一个 GenericJDBCException: 无法打开连接:
Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost' (usi
ng password: NO)
让我有点困惑的是,消息说:(使用密码:NO),
因为我在安装后为 root 设置了密码 MySQL 并且我在配置文件中指定了密码。
我已经尝试解决这个问题几个小时了。
Hibernate 是 4.2.3Final,mysql-connector-java 是 8.0.20.
在您的 hibernate.cfg.xml
中将 "conenction.password" 更改为 "connection.password"
我正在尝试使用 JAVA 中的数据库。 因此我下载了 MySQL,为我的 root 用户设置了密码并创建了一个模式 JH。 数据库位于本地主机端口 3306 上的 运行。
现在我想使用休眠来持久化和访问数据。 我的 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 是 运行 在端口 3306 上 mysqlshow.
现在,当我尝试使用以下方法建立与数据库的连接时:
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
beginTransaction 方法抛出一个 GenericJDBCException: 无法打开连接:
Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost' (usi
ng password: NO)
让我有点困惑的是,消息说:(使用密码:NO), 因为我在安装后为 root 设置了密码 MySQL 并且我在配置文件中指定了密码。
我已经尝试解决这个问题几个小时了。 Hibernate 是 4.2.3Final,mysql-connector-java 是 8.0.20.
在您的 hibernate.cfg.xml
中将 "conenction.password" 更改为 "connection.password"