【发布时间】:2013-10-28 16:13:23
【问题描述】:
我正在尝试使用 Hibernate 3.6.10 和 NetBeans 7.4 连接到 MySQL 数据库,但是当我尝试创建新的“Hibernate 映射向导”时,我回复了以下错误消息:
Unable to connect: Cannot establish a connection jdbc:mysql://localhost:3306/mydbname using apache.org.derby.jdbc.ClientDriver(Unable to find a suitable driver)
这是我的“hibernate.cfg.xml”文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/database</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.connection.password">password</property>
</session-factory>
</hibernate-configuration>
我在这里发现了另一个类似的问题:Hibernate - Cannot connect to DB,但我仍然不明白出了什么问题。
最好的问候。
安德烈亚
【问题讨论】:
-
你的类路径中有
com.mysql.jdbc.Driver类吗? -
类路径中是否也有 hibernate config.prop 文件?
-
嗨 Robin 和 Nambari:我不得不将我的 mysql 驱动程序的“路径”库也配置为 CLASSPATH 变量的 config.prop 路径,但我没有这样做。谢谢。
标签: java mysql hibernate connection driver